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/accessibility/ax_view_state.h" | 7 #include "ui/accessibility/ax_view_state.h" |
8 #include "ui/base/resource/resource_bundle.h" | 8 #include "ui/base/resource/resource_bundle.h" |
9 #include "ui/gfx/color_utils.h" | 9 #include "ui/gfx/color_utils.h" |
10 #include "ui/gfx/geometry/rect.h" | 10 #include "ui/gfx/geometry/rect.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 color_explicitly_set_(false), | 60 color_explicitly_set_(false), |
61 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), | 61 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), |
62 accept_events_(true), | 62 accept_events_(true), |
63 border_accepts_events_(true), | 63 border_accepts_events_(true), |
64 adjust_if_offscreen_(true), | 64 adjust_if_offscreen_(true), |
65 parent_window_(NULL) { | 65 parent_window_(NULL) { |
66 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 66 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
67 UpdateColorsFromTheme(GetNativeTheme()); | 67 UpdateColorsFromTheme(GetNativeTheme()); |
68 } | 68 } |
69 | 69 |
70 BubbleDelegateView::BubbleDelegateView(View* anchor_view, | 70 BubbleDelegateView::BubbleDelegateView( |
71 BubbleBorder::Arrow arrow) | 71 View* anchor_view, |
| 72 BubbleBorder::Arrow arrow) |
72 : close_on_esc_(true), | 73 : close_on_esc_(true), |
73 close_on_deactivate_(true), | 74 close_on_deactivate_(true), |
74 anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()), | 75 anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()), |
75 anchor_widget_(NULL), | 76 anchor_widget_(NULL), |
76 arrow_(arrow), | 77 arrow_(arrow), |
77 shadow_(BubbleBorder::SMALL_SHADOW), | 78 shadow_(BubbleBorder::SMALL_SHADOW), |
78 color_explicitly_set_(false), | 79 color_explicitly_set_(false), |
79 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), | 80 margins_(kDefaultMargin, kDefaultMargin, kDefaultMargin, kDefaultMargin), |
80 accept_events_(true), | 81 accept_events_(true), |
81 border_accepts_events_(true), | 82 border_accepts_events_(true), |
82 adjust_if_offscreen_(true), | 83 adjust_if_offscreen_(true), |
83 parent_window_(NULL), | 84 parent_window_(NULL) { |
84 close_reason_(CloseReason::UNKNOWN) { | |
85 SetAnchorView(anchor_view); | 85 SetAnchorView(anchor_view); |
86 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 86 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
87 UpdateColorsFromTheme(GetNativeTheme()); | 87 UpdateColorsFromTheme(GetNativeTheme()); |
88 } | 88 } |
89 | 89 |
90 BubbleDelegateView::~BubbleDelegateView() { | 90 BubbleDelegateView::~BubbleDelegateView() { |
91 if (GetWidget()) | 91 if (GetWidget()) |
92 GetWidget()->RemoveObserver(this); | 92 GetWidget()->RemoveObserver(this); |
93 SetLayoutManager(NULL); | 93 SetLayoutManager(NULL); |
94 SetAnchorView(NULL); | 94 SetAnchorView(NULL); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 } | 144 } |
145 | 145 |
146 void BubbleDelegateView::GetAccessibleState(ui::AXViewState* state) { | 146 void BubbleDelegateView::GetAccessibleState(ui::AXViewState* state) { |
147 state->role = ui::AX_ROLE_DIALOG; | 147 state->role = ui::AX_ROLE_DIALOG; |
148 } | 148 } |
149 | 149 |
150 const char* BubbleDelegateView::GetClassName() const { | 150 const char* BubbleDelegateView::GetClassName() const { |
151 return kViewClassName; | 151 return kViewClassName; |
152 } | 152 } |
153 | 153 |
154 void BubbleDelegateView::OnWidgetClosing(Widget* widget) { | |
155 DCHECK(GetBubbleFrameView()); | |
156 if (widget == GetWidget() && close_reason_ == CloseReason::UNKNOWN && | |
157 GetBubbleFrameView()->close_button_clicked()) { | |
158 close_reason_ = CloseReason::CLOSE_BUTTON; | |
159 } | |
160 } | |
161 | |
162 void BubbleDelegateView::OnWidgetDestroying(Widget* widget) { | 154 void BubbleDelegateView::OnWidgetDestroying(Widget* widget) { |
163 if (anchor_widget() == widget) | 155 if (anchor_widget() == widget) |
164 SetAnchorView(NULL); | 156 SetAnchorView(NULL); |
165 } | 157 } |
166 | 158 |
167 void BubbleDelegateView::OnWidgetVisibilityChanging(Widget* widget, | 159 void BubbleDelegateView::OnWidgetVisibilityChanging(Widget* widget, |
168 bool visible) { | 160 bool visible) { |
169 #if defined(OS_WIN) | 161 #if defined(OS_WIN) |
170 // On Windows we need to handle this before the bubble is visible or hidden. | 162 // On Windows we need to handle this before the bubble is visible or hidden. |
171 // Please see the comment on the OnWidgetVisibilityChanging function. On | 163 // Please see the comment on the OnWidgetVisibilityChanging function. On |
172 // other platforms it is fine to handle it after the bubble is shown/hidden. | 164 // other platforms it is fine to handle it after the bubble is shown/hidden. |
173 HandleVisibilityChanged(widget, visible); | 165 HandleVisibilityChanged(widget, visible); |
174 #endif | 166 #endif |
175 } | 167 } |
176 | 168 |
177 void BubbleDelegateView::OnWidgetVisibilityChanged(Widget* widget, | 169 void BubbleDelegateView::OnWidgetVisibilityChanged(Widget* widget, |
178 bool visible) { | 170 bool visible) { |
179 #if !defined(OS_WIN) | 171 #if !defined(OS_WIN) |
180 HandleVisibilityChanged(widget, visible); | 172 HandleVisibilityChanged(widget, visible); |
181 #endif | 173 #endif |
182 } | 174 } |
183 | 175 |
184 void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget, | 176 void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget, |
185 bool active) { | 177 bool active) { |
186 if (close_on_deactivate() && widget == GetWidget() && !active) { | 178 if (close_on_deactivate() && widget == GetWidget() && !active) |
187 if (close_reason_ == CloseReason::UNKNOWN) | |
188 close_reason_ = CloseReason::DEACTIVATION; | |
189 GetWidget()->Close(); | 179 GetWidget()->Close(); |
190 } | |
191 } | 180 } |
192 | 181 |
193 void BubbleDelegateView::OnWidgetBoundsChanged(Widget* widget, | 182 void BubbleDelegateView::OnWidgetBoundsChanged(Widget* widget, |
194 const gfx::Rect& new_bounds) { | 183 const gfx::Rect& new_bounds) { |
195 if (GetBubbleFrameView() && anchor_widget() == widget) | 184 if (GetBubbleFrameView() && anchor_widget() == widget) |
196 SizeToContents(); | 185 SizeToContents(); |
197 } | 186 } |
198 | 187 |
199 View* BubbleDelegateView::GetAnchorView() const { | 188 View* BubbleDelegateView::GetAnchorView() const { |
200 return ViewStorage::GetInstance()->RetrieveView(anchor_view_storage_id_); | 189 return ViewStorage::GetInstance()->RetrieveView(anchor_view_storage_id_); |
(...skipping 24 matching lines...) Expand all Loading... |
225 } | 214 } |
226 | 215 |
227 void BubbleDelegateView::OnAnchorBoundsChanged() { | 216 void BubbleDelegateView::OnAnchorBoundsChanged() { |
228 SizeToContents(); | 217 SizeToContents(); |
229 } | 218 } |
230 | 219 |
231 bool BubbleDelegateView::AcceleratorPressed( | 220 bool BubbleDelegateView::AcceleratorPressed( |
232 const ui::Accelerator& accelerator) { | 221 const ui::Accelerator& accelerator) { |
233 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) | 222 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) |
234 return false; | 223 return false; |
235 close_reason_ = CloseReason::ESCAPE; | |
236 GetWidget()->Close(); | 224 GetWidget()->Close(); |
237 return true; | 225 return true; |
238 } | 226 } |
239 | 227 |
240 void BubbleDelegateView::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 228 void BubbleDelegateView::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
241 UpdateColorsFromTheme(theme); | 229 UpdateColorsFromTheme(theme); |
242 } | 230 } |
243 | 231 |
244 void BubbleDelegateView::Init() {} | 232 void BubbleDelegateView::Init() {} |
245 | 233 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 // http://crbug.com/474622 for details. | 315 // http://crbug.com/474622 for details. |
328 if (widget == GetWidget() && visible) { | 316 if (widget == GetWidget() && visible) { |
329 ui::AXViewState state; | 317 ui::AXViewState state; |
330 GetAccessibleState(&state); | 318 GetAccessibleState(&state); |
331 if (state.role == ui::AX_ROLE_ALERT_DIALOG) | 319 if (state.role == ui::AX_ROLE_ALERT_DIALOG) |
332 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 320 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
333 } | 321 } |
334 } | 322 } |
335 | 323 |
336 } // namespace views | 324 } // namespace views |
OLD | NEW |