OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/bubble/bubble_delegate.h" | 5 #include "ui/views/bubble/bubble_delegate.h" |
6 | 6 |
7 #include "ui/base/animation/slide_animation.h" | 7 #include "ui/base/animation/slide_animation.h" |
8 #include "ui/gfx/color_utils.h" | 8 #include "ui/gfx/color_utils.h" |
9 #include "ui/views/bubble/bubble_frame_view.h" | 9 #include "ui/views/bubble/bubble_frame_view.h" |
10 #include "ui/views/widget/widget.h" | 10 #include "ui/views/widget/widget.h" |
11 #include "ui/views/widget/widget_observer.h" | 11 #include "ui/views/widget/widget_observer.h" |
12 | 12 |
13 // The duration of the fade animation in milliseconds. | 13 // The duration of the fade animation in milliseconds. |
14 static const int kHideFadeDurationMS = 200; | 14 static const int kHideFadeDurationMS = 200; |
15 | 15 |
16 // The defaut margin between the content and the inside border, in pixels. | 16 // The defaut margin between the content and the inside border, in pixels. |
17 static const int kDefaultMargin = 6; | 17 static const int kDefaultMargin = 6; |
18 | 18 |
19 namespace views { | 19 namespace views { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // Create a widget to host the bubble. | 23 // Create a widget to host the bubble. |
24 Widget* CreateBubbleWidget(BubbleDelegateView* bubble) { | 24 Widget* CreateBubbleWidget(BubbleDelegateView* bubble) { |
25 Widget* bubble_widget = new Widget(); | 25 Widget* bubble_widget = new Widget(); |
26 Widget::InitParams bubble_params(Widget::InitParams::TYPE_BUBBLE); | 26 Widget::InitParams bubble_params(Widget::InitParams::TYPE_BUBBLE); |
27 bubble_params.delegate = bubble; | 27 bubble_params.delegate = bubble; |
28 bubble_params.transparent = true; | 28 bubble_params.transparent = true; |
| 29 bubble_params.accept_events = bubble->accept_events(); |
29 if (bubble->parent_window()) | 30 if (bubble->parent_window()) |
30 bubble_params.parent = bubble->parent_window(); | 31 bubble_params.parent = bubble->parent_window(); |
31 else | 32 else |
32 bubble_params.parent_widget = bubble->anchor_widget(); | 33 bubble_params.parent_widget = bubble->anchor_widget(); |
33 if (bubble->use_focusless()) | 34 if (bubble->use_focusless()) |
34 bubble_params.can_activate = false; | 35 bubble_params.can_activate = false; |
35 #if defined(OS_WIN) && !defined(USE_AURA) | 36 #if defined(OS_WIN) && !defined(USE_AURA) |
36 bubble_params.type = Widget::InitParams::TYPE_WINDOW_FRAMELESS; | 37 bubble_params.type = Widget::InitParams::TYPE_WINDOW_FRAMELESS; |
37 bubble_params.transparent = false; | 38 bubble_params.transparent = false; |
38 #endif | 39 #endif |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 close_on_deactivate_(true), | 109 close_on_deactivate_(true), |
109 anchor_view_(NULL), | 110 anchor_view_(NULL), |
110 anchor_widget_(NULL), | 111 anchor_widget_(NULL), |
111 move_with_anchor_(false), | 112 move_with_anchor_(false), |
112 arrow_location_(BubbleBorder::TOP_LEFT), | 113 arrow_location_(BubbleBorder::TOP_LEFT), |
113 color_(kBackgroundColor), | 114 color_(kBackgroundColor), |
114 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), | 115 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), |
115 original_opacity_(255), | 116 original_opacity_(255), |
116 border_widget_(NULL), | 117 border_widget_(NULL), |
117 use_focusless_(false), | 118 use_focusless_(false), |
| 119 accept_events_(true), |
118 try_mirroring_arrow_(true), | 120 try_mirroring_arrow_(true), |
119 parent_window_(NULL) { | 121 parent_window_(NULL) { |
120 set_background(Background::CreateSolidBackground(color_)); | 122 set_background(Background::CreateSolidBackground(color_)); |
121 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 123 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
122 } | 124 } |
123 | 125 |
124 BubbleDelegateView::BubbleDelegateView( | 126 BubbleDelegateView::BubbleDelegateView( |
125 View* anchor_view, | 127 View* anchor_view, |
126 BubbleBorder::ArrowLocation arrow_location) | 128 BubbleBorder::ArrowLocation arrow_location) |
127 : close_on_esc_(true), | 129 : close_on_esc_(true), |
128 close_on_deactivate_(true), | 130 close_on_deactivate_(true), |
129 anchor_view_(anchor_view), | 131 anchor_view_(anchor_view), |
130 anchor_widget_(NULL), | 132 anchor_widget_(NULL), |
131 move_with_anchor_(false), | 133 move_with_anchor_(false), |
132 arrow_location_(arrow_location), | 134 arrow_location_(arrow_location), |
133 color_(kBackgroundColor), | 135 color_(kBackgroundColor), |
134 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), | 136 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), |
135 original_opacity_(255), | 137 original_opacity_(255), |
136 border_widget_(NULL), | 138 border_widget_(NULL), |
137 use_focusless_(false), | 139 use_focusless_(false), |
| 140 accept_events_(true), |
138 try_mirroring_arrow_(true), | 141 try_mirroring_arrow_(true), |
139 parent_window_(NULL) { | 142 parent_window_(NULL) { |
140 set_background(Background::CreateSolidBackground(color_)); | 143 set_background(Background::CreateSolidBackground(color_)); |
141 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 144 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
142 } | 145 } |
143 | 146 |
144 BubbleDelegateView::~BubbleDelegateView() { | 147 BubbleDelegateView::~BubbleDelegateView() { |
145 if (anchor_widget() != NULL) | 148 if (anchor_widget() != NULL) |
146 anchor_widget()->RemoveObserver(this); | 149 anchor_widget()->RemoveObserver(this); |
147 anchor_widget_ = NULL; | 150 anchor_widget_ = NULL; |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 | 346 |
344 #if defined(OS_WIN) && !defined(USE_AURA) | 347 #if defined(OS_WIN) && !defined(USE_AURA) |
345 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { | 348 gfx::Rect BubbleDelegateView::GetBubbleClientBounds() const { |
346 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); | 349 gfx::Rect client_bounds(GetBubbleFrameView()->GetBoundsForClientView()); |
347 client_bounds.Offset(border_widget_->GetWindowBoundsInScreen().origin()); | 350 client_bounds.Offset(border_widget_->GetWindowBoundsInScreen().origin()); |
348 return client_bounds; | 351 return client_bounds; |
349 } | 352 } |
350 #endif | 353 #endif |
351 | 354 |
352 } // namespace views | 355 } // namespace views |
OLD | NEW |