OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_dialog_delegate.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "ui/accessibility/ax_view_state.h" | 8 #include "ui/accessibility/ax_view_state.h" |
9 #include "ui/base/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
10 #include "ui/gfx/color_utils.h" | 10 #include "ui/gfx/color_utils.h" |
11 #include "ui/gfx/geometry/rect.h" | 11 #include "ui/gfx/geometry/rect.h" |
12 #include "ui/native_theme/native_theme.h" | 12 #include "ui/native_theme/native_theme.h" |
13 #include "ui/views/bubble/bubble_frame_view.h" | 13 #include "ui/views/bubble/bubble_frame_view.h" |
14 #include "ui/views/focus/view_storage.h" | 14 #include "ui/views/focus/view_storage.h" |
15 #include "ui/views/layout/layout_constants.h" | 15 #include "ui/views/layout/layout_constants.h" |
16 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
17 #include "ui/views/widget/widget_observer.h" | 17 #include "ui/views/widget/widget_observer.h" |
| 18 #include "ui/views/window/dialog_client_view.h" |
18 | 19 |
19 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
20 #include "ui/base/win/shell.h" | 21 #include "ui/base/win/shell.h" |
21 #endif | 22 #endif |
22 | 23 |
23 namespace views { | 24 namespace views { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 // Create a widget to host the bubble. | 28 // Create a widget to host the bubble. |
28 Widget* CreateBubbleWidget(BubbleDelegateView* bubble) { | 29 Widget* CreateBubbleWidget(BubbleDialogDelegateView* bubble) { |
29 Widget* bubble_widget = new Widget(); | 30 Widget* bubble_widget = new Widget(); |
30 Widget::InitParams bubble_params(Widget::InitParams::TYPE_BUBBLE); | 31 Widget::InitParams bubble_params(Widget::InitParams::TYPE_BUBBLE); |
31 bubble_params.delegate = bubble; | 32 bubble_params.delegate = bubble; |
32 bubble_params.opacity = Widget::InitParams::TRANSLUCENT_WINDOW; | 33 bubble_params.opacity = Widget::InitParams::TRANSLUCENT_WINDOW; |
33 bubble_params.accept_events = bubble->accept_events(); | 34 bubble_params.accept_events = bubble->accept_events(); |
34 if (bubble->parent_window()) | 35 if (bubble->parent_window()) |
35 bubble_params.parent = bubble->parent_window(); | 36 bubble_params.parent = bubble->parent_window(); |
36 else if (bubble->anchor_widget()) | 37 else if (bubble->anchor_widget()) |
37 bubble_params.parent = bubble->anchor_widget()->GetNativeView(); | 38 bubble_params.parent = bubble->anchor_widget()->GetNativeView(); |
38 bubble_params.activatable = bubble->CanActivate() ? | 39 bubble_params.activatable = bubble->CanActivate() |
39 Widget::InitParams::ACTIVATABLE_YES : Widget::InitParams::ACTIVATABLE_NO; | 40 ? Widget::InitParams::ACTIVATABLE_YES |
| 41 : Widget::InitParams::ACTIVATABLE_NO; |
40 bubble->OnBeforeBubbleWidgetInit(&bubble_params, bubble_widget); | 42 bubble->OnBeforeBubbleWidgetInit(&bubble_params, bubble_widget); |
41 bubble_widget->Init(bubble_params); | 43 bubble_widget->Init(bubble_params); |
42 if (bubble_params.parent) | 44 if (bubble_params.parent) |
43 bubble_widget->StackAbove(bubble_params.parent); | 45 bubble_widget->StackAbove(bubble_params.parent); |
44 return bubble_widget; | 46 return bubble_widget; |
45 } | 47 } |
46 | 48 |
47 } // namespace | 49 } // namespace |
48 | 50 |
49 // static | 51 // static |
50 const char BubbleDelegateView::kViewClassName[] = "BubbleDelegateView"; | 52 const char BubbleDialogDelegateView::kViewClassName[] = |
| 53 "BubbleDialogDelegateView"; |
51 | 54 |
52 BubbleDelegateView::BubbleDelegateView() | 55 BubbleDialogDelegateView::~BubbleDialogDelegateView() { |
53 : BubbleDelegateView(nullptr, BubbleBorder::TOP_LEFT) {} | |
54 | |
55 BubbleDelegateView::BubbleDelegateView(View* anchor_view, | |
56 BubbleBorder::Arrow arrow) | |
57 : close_on_esc_(true), | |
58 close_on_deactivate_(true), | |
59 anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()), | |
60 anchor_widget_(NULL), | |
61 arrow_(arrow), | |
62 shadow_(BubbleBorder::SMALL_SHADOW), | |
63 color_explicitly_set_(false), | |
64 margins_(kPanelVertMargin, | |
65 kPanelHorizMargin, | |
66 kPanelVertMargin, | |
67 kPanelHorizMargin), | |
68 accept_events_(true), | |
69 border_accepts_events_(true), | |
70 adjust_if_offscreen_(true), | |
71 parent_window_(NULL), | |
72 close_reason_(CloseReason::UNKNOWN) { | |
73 if (anchor_view) | |
74 SetAnchorView(anchor_view); | |
75 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | |
76 UpdateColorsFromTheme(GetNativeTheme()); | |
77 } | |
78 | |
79 BubbleDelegateView::~BubbleDelegateView() { | |
80 if (GetWidget()) | 56 if (GetWidget()) |
81 GetWidget()->RemoveObserver(this); | 57 GetWidget()->RemoveObserver(this); |
82 SetLayoutManager(NULL); | 58 SetLayoutManager(NULL); |
83 SetAnchorView(NULL); | 59 SetAnchorView(NULL); |
84 } | 60 } |
85 | 61 |
86 // static | 62 // static |
87 Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate) { | 63 Widget* BubbleDialogDelegateView::CreateBubble( |
| 64 BubbleDialogDelegateView* bubble_delegate) { |
88 bubble_delegate->Init(); | 65 bubble_delegate->Init(); |
89 // Get the latest anchor widget from the anchor view at bubble creation time. | 66 // Get the latest anchor widget from the anchor view at bubble creation time. |
90 bubble_delegate->SetAnchorView(bubble_delegate->GetAnchorView()); | 67 bubble_delegate->SetAnchorView(bubble_delegate->GetAnchorView()); |
91 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate); | 68 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate); |
92 | 69 |
93 #if defined(OS_WIN) | 70 #if defined(OS_WIN) |
94 // If glass is enabled, the bubble is allowed to extend outside the bounds of | 71 // If glass is enabled, the bubble is allowed to extend outside the bounds of |
95 // the parent frame and let DWM handle compositing. If not, then we don't | 72 // the parent frame and let DWM handle compositing. If not, then we don't |
96 // want to allow the bubble to extend the frame because it will be clipped. | 73 // want to allow the bubble to extend the frame because it will be clipped. |
97 bubble_delegate->set_adjust_if_offscreen(ui::win::IsAeroGlassEnabled()); | 74 bubble_delegate->set_adjust_if_offscreen(ui::win::IsAeroGlassEnabled()); |
98 #elif (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX) | 75 #elif (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX) |
99 // Linux clips bubble windows that extend outside their parent window bounds. | 76 // Linux clips bubble windows that extend outside their parent window bounds. |
100 // Mac never adjusts. | 77 // Mac never adjusts. |
101 bubble_delegate->set_adjust_if_offscreen(false); | 78 bubble_delegate->set_adjust_if_offscreen(false); |
102 #endif | 79 #endif |
103 | 80 |
104 bubble_delegate->SizeToContents(); | 81 bubble_delegate->SizeToContents(); |
105 bubble_widget->AddObserver(bubble_delegate); | 82 bubble_widget->AddObserver(bubble_delegate); |
106 return bubble_widget; | 83 return bubble_widget; |
107 } | 84 } |
108 | 85 |
109 BubbleDelegateView* BubbleDelegateView::AsBubbleDelegate() { | 86 bool BubbleDialogDelegateView::ShouldShowCloseButton() const { |
110 return this; | |
111 } | |
112 | |
113 bool BubbleDelegateView::ShouldShowCloseButton() const { | |
114 return false; | 87 return false; |
115 } | 88 } |
116 | 89 |
117 View* BubbleDelegateView::GetContentsView() { | 90 ClientView* BubbleDialogDelegateView::CreateClientView(Widget* widget) { |
118 return this; | 91 DialogClientView* client = new DialogClientView(widget, GetContentsView()); |
| 92 client->set_button_row_insets(gfx::Insets()); |
| 93 return client; |
119 } | 94 } |
120 | 95 |
121 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView( | 96 NonClientFrameView* BubbleDialogDelegateView::CreateNonClientFrameView( |
122 Widget* widget) { | 97 Widget* widget) { |
123 BubbleFrameView* frame = new BubbleFrameView( | 98 BubbleFrameView* frame = new BubbleFrameView( |
124 gfx::Insets(kPanelVertMargin, kPanelHorizMargin, 0, kPanelHorizMargin), | 99 gfx::Insets(kPanelVertMargin, kPanelHorizMargin, 0, kPanelHorizMargin), |
125 margins()); | 100 margins()); |
126 // Note: In CreateBubble, the call to SizeToContents() will cause | 101 // Note: In CreateBubble, the call to SizeToContents() will cause |
127 // the relayout that this call requires. | 102 // the relayout that this call requires. |
128 frame->SetTitleFontList(GetTitleFontList()); | 103 frame->SetTitleFontList(GetTitleFontList()); |
129 frame->SetFootnoteView(CreateFootnoteView()); | 104 frame->SetFootnoteView(CreateFootnoteView()); |
130 | 105 |
131 BubbleBorder::Arrow adjusted_arrow = arrow(); | 106 BubbleBorder::Arrow adjusted_arrow = arrow(); |
132 if (base::i18n::IsRTL()) | 107 if (base::i18n::IsRTL()) |
133 adjusted_arrow = BubbleBorder::horizontal_mirror(adjusted_arrow); | 108 adjusted_arrow = BubbleBorder::horizontal_mirror(adjusted_arrow); |
134 frame->SetBubbleBorder(scoped_ptr<BubbleBorder>( | 109 frame->SetBubbleBorder(scoped_ptr<BubbleBorder>( |
135 new BubbleBorder(adjusted_arrow, shadow(), color()))); | 110 new BubbleBorder(adjusted_arrow, shadow(), color()))); |
136 return frame; | 111 return frame; |
137 } | 112 } |
138 | 113 |
139 void BubbleDelegateView::GetAccessibleState(ui::AXViewState* state) { | 114 void BubbleDialogDelegateView::GetAccessibleState(ui::AXViewState* state) { |
140 state->role = ui::AX_ROLE_DIALOG; | 115 state->role = ui::AX_ROLE_DIALOG; |
141 } | 116 } |
142 | 117 |
143 const char* BubbleDelegateView::GetClassName() const { | 118 const char* BubbleDialogDelegateView::GetClassName() const { |
144 return kViewClassName; | 119 return kViewClassName; |
145 } | 120 } |
146 | 121 |
147 void BubbleDelegateView::OnWidgetClosing(Widget* widget) { | 122 void BubbleDialogDelegateView::OnWidgetClosing(Widget* widget) { |
148 DCHECK(GetBubbleFrameView()); | 123 DCHECK(GetBubbleFrameView()); |
149 if (widget == GetWidget() && close_reason_ == CloseReason::UNKNOWN && | 124 if (widget == GetWidget() && close_reason_ == CloseReason::UNKNOWN && |
150 GetBubbleFrameView()->close_button_clicked()) { | 125 GetBubbleFrameView()->close_button_clicked()) { |
151 close_reason_ = CloseReason::CLOSE_BUTTON; | 126 close_reason_ = CloseReason::CLOSE_BUTTON; |
152 } | 127 } |
153 } | 128 } |
154 | 129 |
155 void BubbleDelegateView::OnWidgetDestroying(Widget* widget) { | 130 void BubbleDialogDelegateView::OnWidgetDestroying(Widget* widget) { |
156 if (anchor_widget() == widget) | 131 if (anchor_widget() == widget) |
157 SetAnchorView(NULL); | 132 SetAnchorView(NULL); |
158 } | 133 } |
159 | 134 |
160 void BubbleDelegateView::OnWidgetVisibilityChanging(Widget* widget, | 135 void BubbleDialogDelegateView::OnWidgetVisibilityChanging(Widget* widget, |
161 bool visible) { | 136 bool visible) { |
162 #if defined(OS_WIN) | 137 #if defined(OS_WIN) |
163 // On Windows we need to handle this before the bubble is visible or hidden. | 138 // On Windows we need to handle this before the bubble is visible or hidden. |
164 // Please see the comment on the OnWidgetVisibilityChanging function. On | 139 // Please see the comment on the OnWidgetVisibilityChanging function. On |
165 // other platforms it is fine to handle it after the bubble is shown/hidden. | 140 // other platforms it is fine to handle it after the bubble is shown/hidden. |
166 HandleVisibilityChanged(widget, visible); | 141 HandleVisibilityChanged(widget, visible); |
167 #endif | 142 #endif |
168 } | 143 } |
169 | 144 |
170 void BubbleDelegateView::OnWidgetVisibilityChanged(Widget* widget, | 145 void BubbleDialogDelegateView::OnWidgetVisibilityChanged(Widget* widget, |
171 bool visible) { | 146 bool visible) { |
172 #if !defined(OS_WIN) | 147 #if !defined(OS_WIN) |
173 HandleVisibilityChanged(widget, visible); | 148 HandleVisibilityChanged(widget, visible); |
174 #endif | 149 #endif |
175 } | 150 } |
176 | 151 |
177 void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget, | 152 void BubbleDialogDelegateView::OnWidgetActivationChanged(Widget* widget, |
178 bool active) { | 153 bool active) { |
179 if (close_on_deactivate() && widget == GetWidget() && !active) { | 154 if (close_on_deactivate() && widget == GetWidget() && !active) { |
180 if (close_reason_ == CloseReason::UNKNOWN) | 155 if (close_reason_ == CloseReason::UNKNOWN) |
181 close_reason_ = CloseReason::DEACTIVATION; | 156 close_reason_ = CloseReason::DEACTIVATION; |
182 GetWidget()->Close(); | 157 GetWidget()->Close(); |
183 } | 158 } |
184 } | 159 } |
185 | 160 |
186 void BubbleDelegateView::OnWidgetBoundsChanged(Widget* widget, | 161 void BubbleDialogDelegateView::OnWidgetBoundsChanged( |
187 const gfx::Rect& new_bounds) { | 162 Widget* widget, |
| 163 const gfx::Rect& new_bounds) { |
188 if (GetBubbleFrameView() && anchor_widget() == widget) | 164 if (GetBubbleFrameView() && anchor_widget() == widget) |
189 SizeToContents(); | 165 SizeToContents(); |
190 } | 166 } |
191 | 167 |
192 View* BubbleDelegateView::GetAnchorView() const { | 168 View* BubbleDialogDelegateView::GetAnchorView() const { |
193 return ViewStorage::GetInstance()->RetrieveView(anchor_view_storage_id_); | 169 return ViewStorage::GetInstance()->RetrieveView(anchor_view_storage_id_); |
194 } | 170 } |
195 | 171 |
196 gfx::Rect BubbleDelegateView::GetAnchorRect() const { | 172 gfx::Rect BubbleDialogDelegateView::GetAnchorRect() const { |
197 if (!GetAnchorView()) | 173 if (!GetAnchorView()) |
198 return anchor_rect_; | 174 return anchor_rect_; |
199 | 175 |
200 anchor_rect_ = GetAnchorView()->GetBoundsInScreen(); | 176 anchor_rect_ = GetAnchorView()->GetBoundsInScreen(); |
201 anchor_rect_.Inset(anchor_view_insets_); | 177 anchor_rect_.Inset(anchor_view_insets_); |
202 return anchor_rect_; | 178 return anchor_rect_; |
203 } | 179 } |
204 | 180 |
205 void BubbleDelegateView::OnBeforeBubbleWidgetInit(Widget::InitParams* params, | 181 void BubbleDialogDelegateView::OnBeforeBubbleWidgetInit( |
206 Widget* widget) const { | 182 Widget::InitParams* params, |
207 } | 183 Widget* widget) const {} |
208 | 184 |
209 scoped_ptr<View> BubbleDelegateView::CreateFootnoteView() { | 185 void BubbleDialogDelegateView::UseCompactMargins() { |
210 return nullptr; | |
211 } | |
212 | |
213 void BubbleDelegateView::UseCompactMargins() { | |
214 const int kCompactMargin = 6; | 186 const int kCompactMargin = 6; |
215 margins_.Set(kCompactMargin, kCompactMargin, kCompactMargin, kCompactMargin); | 187 margins_.Set(kCompactMargin, kCompactMargin, kCompactMargin, kCompactMargin); |
216 } | 188 } |
217 | 189 |
218 void BubbleDelegateView::SetAlignment(BubbleBorder::BubbleAlignment alignment) { | 190 void BubbleDialogDelegateView::SetAlignment( |
| 191 BubbleBorder::BubbleAlignment alignment) { |
219 GetBubbleFrameView()->bubble_border()->set_alignment(alignment); | 192 GetBubbleFrameView()->bubble_border()->set_alignment(alignment); |
220 SizeToContents(); | 193 SizeToContents(); |
221 } | 194 } |
222 | 195 |
223 void BubbleDelegateView::SetArrowPaintType( | 196 void BubbleDialogDelegateView::SetArrowPaintType( |
224 BubbleBorder::ArrowPaintType paint_type) { | 197 BubbleBorder::ArrowPaintType paint_type) { |
225 GetBubbleFrameView()->bubble_border()->set_paint_arrow(paint_type); | 198 GetBubbleFrameView()->bubble_border()->set_paint_arrow(paint_type); |
226 SizeToContents(); | 199 SizeToContents(); |
227 } | 200 } |
228 | 201 |
229 void BubbleDelegateView::OnAnchorBoundsChanged() { | 202 void BubbleDialogDelegateView::OnAnchorBoundsChanged() { |
230 SizeToContents(); | 203 SizeToContents(); |
231 } | 204 } |
232 | 205 |
233 bool BubbleDelegateView::AcceleratorPressed( | 206 BubbleDialogDelegateView::BubbleDialogDelegateView() |
| 207 : BubbleDialogDelegateView(nullptr, BubbleBorder::TOP_LEFT) {} |
| 208 |
| 209 BubbleDialogDelegateView::BubbleDialogDelegateView(View* anchor_view, |
| 210 BubbleBorder::Arrow arrow) |
| 211 : close_on_esc_(true), |
| 212 close_on_deactivate_(true), |
| 213 anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()), |
| 214 anchor_widget_(NULL), |
| 215 arrow_(arrow), |
| 216 shadow_(BubbleBorder::SMALL_SHADOW), |
| 217 color_explicitly_set_(false), |
| 218 margins_(kPanelVertMargin, |
| 219 kPanelHorizMargin, |
| 220 kPanelVertMargin, |
| 221 kPanelHorizMargin), |
| 222 accept_events_(true), |
| 223 border_accepts_events_(true), |
| 224 adjust_if_offscreen_(true), |
| 225 parent_window_(NULL), |
| 226 close_reason_(CloseReason::UNKNOWN) { |
| 227 if (anchor_view) |
| 228 SetAnchorView(anchor_view); |
| 229 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
| 230 UpdateColorsFromTheme(GetNativeTheme()); |
| 231 } |
| 232 |
| 233 gfx::Rect BubbleDialogDelegateView::GetBubbleBounds() { |
| 234 // The argument rect has its origin at the bubble's arrow anchor point; |
| 235 // its size is the preferred size of the bubble's client view (this view). |
| 236 bool anchor_minimized = anchor_widget() && anchor_widget()->IsMinimized(); |
| 237 return GetBubbleFrameView()->GetUpdatedWindowBounds( |
| 238 GetAnchorRect(), GetWidget()->client_view()->GetPreferredSize(), |
| 239 adjust_if_offscreen_ && !anchor_minimized); |
| 240 } |
| 241 |
| 242 const gfx::FontList& BubbleDialogDelegateView::GetTitleFontList() const { |
| 243 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 244 return rb.GetFontList(ui::ResourceBundle::MediumFont); |
| 245 } |
| 246 |
| 247 bool BubbleDialogDelegateView::AcceleratorPressed( |
234 const ui::Accelerator& accelerator) { | 248 const ui::Accelerator& accelerator) { |
235 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) | 249 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) |
236 return false; | 250 return false; |
237 close_reason_ = CloseReason::ESCAPE; | 251 close_reason_ = CloseReason::ESCAPE; |
238 GetWidget()->Close(); | 252 GetWidget()->Close(); |
239 return true; | 253 return true; |
240 } | 254 } |
241 | 255 |
242 void BubbleDelegateView::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 256 void BubbleDialogDelegateView::OnNativeThemeChanged( |
| 257 const ui::NativeTheme* theme) { |
243 UpdateColorsFromTheme(theme); | 258 UpdateColorsFromTheme(theme); |
244 } | 259 } |
245 | 260 |
246 void BubbleDelegateView::Init() {} | 261 void BubbleDialogDelegateView::Init() {} |
247 | 262 |
248 void BubbleDelegateView::SetAnchorView(View* anchor_view) { | 263 void BubbleDialogDelegateView::SetAnchorView(View* anchor_view) { |
249 // When the anchor view gets set the associated anchor widget might | 264 // When the anchor view gets set the associated anchor widget might |
250 // change as well. | 265 // change as well. |
251 if (!anchor_view || anchor_widget() != anchor_view->GetWidget()) { | 266 if (!anchor_view || anchor_widget() != anchor_view->GetWidget()) { |
252 if (anchor_widget()) { | 267 if (anchor_widget()) { |
253 anchor_widget_->RemoveObserver(this); | 268 anchor_widget_->RemoveObserver(this); |
254 anchor_widget_ = NULL; | 269 anchor_widget_ = NULL; |
255 } | 270 } |
256 if (anchor_view) { | 271 if (anchor_view) { |
257 anchor_widget_ = anchor_view->GetWidget(); | 272 anchor_widget_ = anchor_view->GetWidget(); |
258 if (anchor_widget_) | 273 if (anchor_widget_) |
259 anchor_widget_->AddObserver(this); | 274 anchor_widget_->AddObserver(this); |
260 } | 275 } |
261 } | 276 } |
262 | 277 |
263 // Remove the old storage item and set the new (if there is one). | 278 // Remove the old storage item and set the new (if there is one). |
264 ViewStorage* view_storage = ViewStorage::GetInstance(); | 279 ViewStorage* view_storage = ViewStorage::GetInstance(); |
265 if (view_storage->RetrieveView(anchor_view_storage_id_)) | 280 if (view_storage->RetrieveView(anchor_view_storage_id_)) |
266 view_storage->RemoveView(anchor_view_storage_id_); | 281 view_storage->RemoveView(anchor_view_storage_id_); |
267 if (anchor_view) | 282 if (anchor_view) |
268 view_storage->StoreView(anchor_view_storage_id_, anchor_view); | 283 view_storage->StoreView(anchor_view_storage_id_, anchor_view); |
269 | 284 |
270 // Do not update anchoring for NULL views; this could indicate that our | 285 // Do not update anchoring for NULL views; this could indicate that our |
271 // NativeWindow is being destroyed, so it would be dangerous for us to update | 286 // NativeWindow is being destroyed, so it would be dangerous for us to update |
272 // our anchor bounds at that point. (It's safe to skip this, since if we were | 287 // our anchor bounds at that point. (It's safe to skip this, since if we were |
273 // to update the bounds when |anchor_view| is NULL, the bubble won't move.) | 288 // to update the bounds when |anchor_view| is NULL, the bubble won't move.) |
274 if (anchor_view && GetWidget()) | 289 if (anchor_view && GetWidget()) |
275 OnAnchorBoundsChanged(); | 290 OnAnchorBoundsChanged(); |
276 } | 291 } |
277 | 292 |
278 void BubbleDelegateView::SetAnchorRect(const gfx::Rect& rect) { | 293 void BubbleDialogDelegateView::SetAnchorRect(const gfx::Rect& rect) { |
279 anchor_rect_ = rect; | 294 anchor_rect_ = rect; |
280 if (GetWidget()) | 295 if (GetWidget()) |
281 OnAnchorBoundsChanged(); | 296 OnAnchorBoundsChanged(); |
282 } | 297 } |
283 | 298 |
284 void BubbleDelegateView::SizeToContents() { | 299 void BubbleDialogDelegateView::SizeToContents() { |
285 GetWidget()->SetBounds(GetBubbleBounds()); | 300 GetWidget()->SetBounds(GetBubbleBounds()); |
286 } | 301 } |
287 | 302 |
288 BubbleFrameView* BubbleDelegateView::GetBubbleFrameView() const { | 303 BubbleFrameView* BubbleDialogDelegateView::GetBubbleFrameView() const { |
289 const NonClientView* view = | 304 const NonClientView* view = |
290 GetWidget() ? GetWidget()->non_client_view() : NULL; | 305 GetWidget() ? GetWidget()->non_client_view() : NULL; |
291 return view ? static_cast<BubbleFrameView*>(view->frame_view()) : NULL; | 306 return view ? static_cast<BubbleFrameView*>(view->frame_view()) : NULL; |
292 } | 307 } |
293 | 308 |
294 gfx::Rect BubbleDelegateView::GetBubbleBounds() { | 309 void BubbleDialogDelegateView::UpdateColorsFromTheme( |
295 // The argument rect has its origin at the bubble's arrow anchor point; | 310 const ui::NativeTheme* theme) { |
296 // its size is the preferred size of the bubble's client view (this view). | |
297 bool anchor_minimized = anchor_widget() && anchor_widget()->IsMinimized(); | |
298 return GetBubbleFrameView()->GetUpdatedWindowBounds(GetAnchorRect(), | |
299 GetPreferredSize(), adjust_if_offscreen_ && !anchor_minimized); | |
300 } | |
301 | |
302 const gfx::FontList& BubbleDelegateView::GetTitleFontList() const { | |
303 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
304 return rb.GetFontList(ui::ResourceBundle::MediumFont); | |
305 } | |
306 | |
307 | |
308 void BubbleDelegateView::UpdateColorsFromTheme(const ui::NativeTheme* theme) { | |
309 if (!color_explicitly_set_) | 311 if (!color_explicitly_set_) |
310 color_ = theme->GetSystemColor(ui::NativeTheme::kColorId_BubbleBackground); | 312 color_ = theme->GetSystemColor(ui::NativeTheme::kColorId_BubbleBackground); |
311 set_background(Background::CreateSolidBackground(color())); | 313 set_background(Background::CreateSolidBackground(color())); |
312 BubbleFrameView* frame_view = GetBubbleFrameView(); | 314 BubbleFrameView* frame_view = GetBubbleFrameView(); |
313 if (frame_view) | 315 if (frame_view) |
314 frame_view->bubble_border()->set_background_color(color()); | 316 frame_view->bubble_border()->set_background_color(color()); |
315 } | 317 } |
316 | 318 |
317 void BubbleDelegateView::HandleVisibilityChanged(Widget* widget, bool visible) { | 319 void BubbleDialogDelegateView::HandleVisibilityChanged(Widget* widget, |
| 320 bool visible) { |
318 if (widget == GetWidget() && anchor_widget() && | 321 if (widget == GetWidget() && anchor_widget() && |
319 anchor_widget()->GetTopLevelWidget()) { | 322 anchor_widget()->GetTopLevelWidget()) { |
320 if (visible) | 323 if (visible) |
321 anchor_widget()->GetTopLevelWidget()->DisableInactiveRendering(); | 324 anchor_widget()->GetTopLevelWidget()->DisableInactiveRendering(); |
322 else | 325 else |
323 anchor_widget()->GetTopLevelWidget()->EnableInactiveRendering(); | 326 anchor_widget()->GetTopLevelWidget()->EnableInactiveRendering(); |
324 } | 327 } |
325 | 328 |
326 // Fire AX_EVENT_ALERT for bubbles marked as AX_ROLE_ALERT_DIALOG; this | 329 // Fire AX_EVENT_ALERT for bubbles marked as AX_ROLE_ALERT_DIALOG; this |
327 // instructs accessibility tools to read the bubble in its entirety rather | 330 // instructs accessibility tools to read the bubble in its entirety rather |
328 // than just its title and initially focused view. See | 331 // than just its title and initially focused view. See |
329 // http://crbug.com/474622 for details. | 332 // http://crbug.com/474622 for details. |
330 if (widget == GetWidget() && visible) { | 333 if (widget == GetWidget() && visible) { |
331 ui::AXViewState state; | 334 ui::AXViewState state; |
332 GetAccessibleState(&state); | 335 GetAccessibleState(&state); |
333 if (state.role == ui::AX_ROLE_ALERT_DIALOG) | 336 if (state.role == ui::AX_ROLE_ALERT_DIALOG) |
334 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 337 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
335 } | 338 } |
336 } | 339 } |
337 | 340 |
338 } // namespace views | 341 } // namespace views |
OLD | NEW |