Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(676)

Side by Side Diff: ui/views/bubble/bubble_dialog_delegate.cc

Issue 1717453003: Introduce BubbleDialogDelegateView, which extends DialogDelegateView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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()
msw 2016/02/22 21:43:56 nit: reorder to match decl (ditto for other ctor)
Evan Stade 2016/02/22 22:58:23 Done.
53 : BubbleDelegateView(nullptr, BubbleBorder::TOP_LEFT) {} 56 : BubbleDialogDelegateView(nullptr, BubbleBorder::TOP_LEFT) {}
54 57
55 BubbleDelegateView::BubbleDelegateView(View* anchor_view, 58 BubbleDialogDelegateView::BubbleDialogDelegateView(View* anchor_view,
56 BubbleBorder::Arrow arrow) 59 BubbleBorder::Arrow arrow)
57 : close_on_esc_(true), 60 : close_on_esc_(true),
58 close_on_deactivate_(true), 61 close_on_deactivate_(true),
59 anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()), 62 anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()),
60 anchor_widget_(NULL), 63 anchor_widget_(NULL),
61 arrow_(arrow), 64 arrow_(arrow),
62 shadow_(BubbleBorder::SMALL_SHADOW), 65 shadow_(BubbleBorder::SMALL_SHADOW),
63 color_explicitly_set_(false), 66 color_explicitly_set_(false),
64 margins_(kPanelVertMargin, 67 margins_(kPanelVertMargin,
65 kPanelHorizMargin, 68 kPanelHorizMargin,
66 kPanelVertMargin, 69 kPanelVertMargin,
67 kPanelHorizMargin), 70 kPanelHorizMargin),
68 accept_events_(true), 71 accept_events_(true),
69 border_accepts_events_(true), 72 border_accepts_events_(true),
70 adjust_if_offscreen_(true), 73 adjust_if_offscreen_(true),
71 parent_window_(NULL), 74 parent_window_(NULL),
72 close_reason_(CloseReason::UNKNOWN) { 75 close_reason_(CloseReason::UNKNOWN) {
73 if (anchor_view) 76 if (anchor_view)
74 SetAnchorView(anchor_view); 77 SetAnchorView(anchor_view);
75 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); 78 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
76 UpdateColorsFromTheme(GetNativeTheme()); 79 UpdateColorsFromTheme(GetNativeTheme());
77 } 80 }
78 81
79 BubbleDelegateView::~BubbleDelegateView() { 82 BubbleDialogDelegateView::~BubbleDialogDelegateView() {
80 if (GetWidget()) 83 if (GetWidget())
81 GetWidget()->RemoveObserver(this); 84 GetWidget()->RemoveObserver(this);
82 SetLayoutManager(NULL); 85 SetLayoutManager(NULL);
83 SetAnchorView(NULL); 86 SetAnchorView(NULL);
84 } 87 }
85 88
86 // static 89 // static
87 Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate) { 90 Widget* BubbleDialogDelegateView::CreateBubble(
91 BubbleDialogDelegateView* bubble_delegate) {
88 bubble_delegate->Init(); 92 bubble_delegate->Init();
89 // Get the latest anchor widget from the anchor view at bubble creation time. 93 // Get the latest anchor widget from the anchor view at bubble creation time.
90 bubble_delegate->SetAnchorView(bubble_delegate->GetAnchorView()); 94 bubble_delegate->SetAnchorView(bubble_delegate->GetAnchorView());
91 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate); 95 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate);
92 96
93 #if defined(OS_WIN) 97 #if defined(OS_WIN)
94 // If glass is enabled, the bubble is allowed to extend outside the bounds of 98 // 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 99 // 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. 100 // want to allow the bubble to extend the frame because it will be clipped.
97 bubble_delegate->set_adjust_if_offscreen(ui::win::IsAeroGlassEnabled()); 101 bubble_delegate->set_adjust_if_offscreen(ui::win::IsAeroGlassEnabled());
98 #elif (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX) 102 #elif (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX)
99 // Linux clips bubble windows that extend outside their parent window bounds. 103 // Linux clips bubble windows that extend outside their parent window bounds.
100 // Mac never adjusts. 104 // Mac never adjusts.
101 bubble_delegate->set_adjust_if_offscreen(false); 105 bubble_delegate->set_adjust_if_offscreen(false);
102 #endif 106 #endif
103 107
104 bubble_delegate->SizeToContents(); 108 bubble_delegate->SizeToContents();
105 bubble_widget->AddObserver(bubble_delegate); 109 bubble_widget->AddObserver(bubble_delegate);
106 return bubble_widget; 110 return bubble_widget;
107 } 111 }
108 112
109 BubbleDelegateView* BubbleDelegateView::AsBubbleDelegate() { 113 bool BubbleDialogDelegateView::ShouldShowCloseButton() const {
110 return this;
111 }
112
113 bool BubbleDelegateView::ShouldShowCloseButton() const {
114 return false; 114 return false;
115 } 115 }
116 116
117 View* BubbleDelegateView::GetContentsView() { 117 ClientView* BubbleDialogDelegateView::CreateClientView(Widget* widget) {
118 return this; 118 DialogClientView* client = new DialogClientView(widget, GetContentsView());
119 client->set_button_row_insets(gfx::Insets());
msw 2016/02/22 21:43:56 Why do we want empty insets here?
Evan Stade 2016/02/22 22:58:23 Dialogs don't inset the client view at all. Bubble
msw 2016/02/22 23:24:57 Acknowledged.
120 return client;
119 } 121 }
120 122
121 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView( 123 NonClientFrameView* BubbleDialogDelegateView::CreateNonClientFrameView(
122 Widget* widget) { 124 Widget* widget) {
123 BubbleFrameView* frame = new BubbleFrameView( 125 BubbleFrameView* frame = new BubbleFrameView(
124 gfx::Insets(kPanelVertMargin, kPanelHorizMargin, 0, kPanelHorizMargin), 126 gfx::Insets(kPanelVertMargin, kPanelHorizMargin, 0, kPanelHorizMargin),
125 margins()); 127 margins());
126 // Note: In CreateBubble, the call to SizeToContents() will cause 128 // Note: In CreateBubble, the call to SizeToContents() will cause
127 // the relayout that this call requires. 129 // the relayout that this call requires.
128 frame->SetTitleFontList(GetTitleFontList()); 130 frame->SetTitleFontList(GetTitleFontList());
129 frame->SetFootnoteView(CreateFootnoteView()); 131 frame->SetFootnoteView(CreateFootnoteView());
130 132
131 BubbleBorder::Arrow adjusted_arrow = arrow(); 133 BubbleBorder::Arrow adjusted_arrow = arrow();
132 if (base::i18n::IsRTL()) 134 if (base::i18n::IsRTL())
133 adjusted_arrow = BubbleBorder::horizontal_mirror(adjusted_arrow); 135 adjusted_arrow = BubbleBorder::horizontal_mirror(adjusted_arrow);
134 frame->SetBubbleBorder(scoped_ptr<BubbleBorder>( 136 frame->SetBubbleBorder(scoped_ptr<BubbleBorder>(
135 new BubbleBorder(adjusted_arrow, shadow(), color()))); 137 new BubbleBorder(adjusted_arrow, shadow(), color())));
136 return frame; 138 return frame;
137 } 139 }
138 140
139 void BubbleDelegateView::GetAccessibleState(ui::AXViewState* state) { 141 void BubbleDialogDelegateView::GetAccessibleState(ui::AXViewState* state) {
140 state->role = ui::AX_ROLE_DIALOG; 142 state->role = ui::AX_ROLE_DIALOG;
141 } 143 }
142 144
143 const char* BubbleDelegateView::GetClassName() const { 145 const char* BubbleDialogDelegateView::GetClassName() const {
144 return kViewClassName; 146 return kViewClassName;
145 } 147 }
146 148
147 void BubbleDelegateView::OnWidgetClosing(Widget* widget) { 149 void BubbleDialogDelegateView::OnWidgetClosing(Widget* widget) {
148 DCHECK(GetBubbleFrameView()); 150 DCHECK(GetBubbleFrameView());
149 if (widget == GetWidget() && close_reason_ == CloseReason::UNKNOWN && 151 if (widget == GetWidget() && close_reason_ == CloseReason::UNKNOWN &&
150 GetBubbleFrameView()->close_button_clicked()) { 152 GetBubbleFrameView()->close_button_clicked()) {
151 close_reason_ = CloseReason::CLOSE_BUTTON; 153 close_reason_ = CloseReason::CLOSE_BUTTON;
152 } 154 }
153 } 155 }
154 156
155 void BubbleDelegateView::OnWidgetDestroying(Widget* widget) { 157 void BubbleDialogDelegateView::OnWidgetDestroying(Widget* widget) {
156 if (anchor_widget() == widget) 158 if (anchor_widget() == widget)
157 SetAnchorView(NULL); 159 SetAnchorView(NULL);
158 } 160 }
159 161
160 void BubbleDelegateView::OnWidgetVisibilityChanging(Widget* widget, 162 void BubbleDialogDelegateView::OnWidgetVisibilityChanging(Widget* widget,
161 bool visible) { 163 bool visible) {
162 #if defined(OS_WIN) 164 #if defined(OS_WIN)
163 // On Windows we need to handle this before the bubble is visible or hidden. 165 // On Windows we need to handle this before the bubble is visible or hidden.
164 // Please see the comment on the OnWidgetVisibilityChanging function. On 166 // Please see the comment on the OnWidgetVisibilityChanging function. On
165 // other platforms it is fine to handle it after the bubble is shown/hidden. 167 // other platforms it is fine to handle it after the bubble is shown/hidden.
166 HandleVisibilityChanged(widget, visible); 168 HandleVisibilityChanged(widget, visible);
167 #endif 169 #endif
168 } 170 }
169 171
170 void BubbleDelegateView::OnWidgetVisibilityChanged(Widget* widget, 172 void BubbleDialogDelegateView::OnWidgetVisibilityChanged(Widget* widget,
171 bool visible) { 173 bool visible) {
172 #if !defined(OS_WIN) 174 #if !defined(OS_WIN)
173 HandleVisibilityChanged(widget, visible); 175 HandleVisibilityChanged(widget, visible);
174 #endif 176 #endif
175 } 177 }
176 178
177 void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget, 179 void BubbleDialogDelegateView::OnWidgetActivationChanged(Widget* widget,
178 bool active) { 180 bool active) {
179 if (close_on_deactivate() && widget == GetWidget() && !active) { 181 if (close_on_deactivate() && widget == GetWidget() && !active) {
180 if (close_reason_ == CloseReason::UNKNOWN) 182 if (close_reason_ == CloseReason::UNKNOWN)
181 close_reason_ = CloseReason::DEACTIVATION; 183 close_reason_ = CloseReason::DEACTIVATION;
182 GetWidget()->Close(); 184 GetWidget()->Close();
183 } 185 }
184 } 186 }
185 187
186 void BubbleDelegateView::OnWidgetBoundsChanged(Widget* widget, 188 void BubbleDialogDelegateView::OnWidgetBoundsChanged(
187 const gfx::Rect& new_bounds) { 189 Widget* widget,
190 const gfx::Rect& new_bounds) {
188 if (GetBubbleFrameView() && anchor_widget() == widget) 191 if (GetBubbleFrameView() && anchor_widget() == widget)
189 SizeToContents(); 192 SizeToContents();
190 } 193 }
191 194
192 View* BubbleDelegateView::GetAnchorView() const { 195 View* BubbleDialogDelegateView::GetAnchorView() const {
193 return ViewStorage::GetInstance()->RetrieveView(anchor_view_storage_id_); 196 return ViewStorage::GetInstance()->RetrieveView(anchor_view_storage_id_);
194 } 197 }
195 198
196 gfx::Rect BubbleDelegateView::GetAnchorRect() const { 199 gfx::Rect BubbleDialogDelegateView::GetAnchorRect() const {
197 if (!GetAnchorView()) 200 if (!GetAnchorView())
198 return anchor_rect_; 201 return anchor_rect_;
199 202
200 anchor_rect_ = GetAnchorView()->GetBoundsInScreen(); 203 anchor_rect_ = GetAnchorView()->GetBoundsInScreen();
201 anchor_rect_.Inset(anchor_view_insets_); 204 anchor_rect_.Inset(anchor_view_insets_);
202 return anchor_rect_; 205 return anchor_rect_;
203 } 206 }
204 207
205 void BubbleDelegateView::OnBeforeBubbleWidgetInit(Widget::InitParams* params, 208 void BubbleDialogDelegateView::OnBeforeBubbleWidgetInit(
206 Widget* widget) const { 209 Widget::InitParams* params,
207 } 210 Widget* widget) const {}
208 211
209 scoped_ptr<View> BubbleDelegateView::CreateFootnoteView() { 212 void BubbleDialogDelegateView::UseCompactMargins() {
210 return nullptr;
211 }
212
213 void BubbleDelegateView::UseCompactMargins() {
214 const int kCompactMargin = 6; 213 const int kCompactMargin = 6;
215 margins_.Set(kCompactMargin, kCompactMargin, kCompactMargin, kCompactMargin); 214 margins_.Set(kCompactMargin, kCompactMargin, kCompactMargin, kCompactMargin);
216 } 215 }
217 216
218 void BubbleDelegateView::SetAlignment(BubbleBorder::BubbleAlignment alignment) { 217 void BubbleDialogDelegateView::SetAlignment(
218 BubbleBorder::BubbleAlignment alignment) {
219 GetBubbleFrameView()->bubble_border()->set_alignment(alignment); 219 GetBubbleFrameView()->bubble_border()->set_alignment(alignment);
220 SizeToContents(); 220 SizeToContents();
221 } 221 }
222 222
223 void BubbleDelegateView::SetArrowPaintType( 223 void BubbleDialogDelegateView::SetArrowPaintType(
224 BubbleBorder::ArrowPaintType paint_type) { 224 BubbleBorder::ArrowPaintType paint_type) {
225 GetBubbleFrameView()->bubble_border()->set_paint_arrow(paint_type); 225 GetBubbleFrameView()->bubble_border()->set_paint_arrow(paint_type);
226 SizeToContents(); 226 SizeToContents();
227 } 227 }
228 228
229 void BubbleDelegateView::OnAnchorBoundsChanged() { 229 void BubbleDialogDelegateView::OnAnchorBoundsChanged() {
230 SizeToContents(); 230 SizeToContents();
231 } 231 }
232 232
233 bool BubbleDelegateView::AcceleratorPressed( 233 bool BubbleDialogDelegateView::AcceleratorPressed(
234 const ui::Accelerator& accelerator) { 234 const ui::Accelerator& accelerator) {
235 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) 235 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE)
236 return false; 236 return false;
237 close_reason_ = CloseReason::ESCAPE; 237 close_reason_ = CloseReason::ESCAPE;
238 GetWidget()->Close(); 238 GetWidget()->Close();
239 return true; 239 return true;
240 } 240 }
241 241
242 void BubbleDelegateView::OnNativeThemeChanged(const ui::NativeTheme* theme) { 242 void BubbleDialogDelegateView::OnNativeThemeChanged(
243 const ui::NativeTheme* theme) {
243 UpdateColorsFromTheme(theme); 244 UpdateColorsFromTheme(theme);
244 } 245 }
245 246
246 void BubbleDelegateView::Init() {} 247 void BubbleDialogDelegateView::Init() {}
247 248
248 void BubbleDelegateView::SetAnchorView(View* anchor_view) { 249 void BubbleDialogDelegateView::SetAnchorView(View* anchor_view) {
249 // When the anchor view gets set the associated anchor widget might 250 // When the anchor view gets set the associated anchor widget might
250 // change as well. 251 // change as well.
251 if (!anchor_view || anchor_widget() != anchor_view->GetWidget()) { 252 if (!anchor_view || anchor_widget() != anchor_view->GetWidget()) {
252 if (anchor_widget()) { 253 if (anchor_widget()) {
253 anchor_widget_->RemoveObserver(this); 254 anchor_widget_->RemoveObserver(this);
254 anchor_widget_ = NULL; 255 anchor_widget_ = NULL;
255 } 256 }
256 if (anchor_view) { 257 if (anchor_view) {
257 anchor_widget_ = anchor_view->GetWidget(); 258 anchor_widget_ = anchor_view->GetWidget();
258 if (anchor_widget_) 259 if (anchor_widget_)
259 anchor_widget_->AddObserver(this); 260 anchor_widget_->AddObserver(this);
260 } 261 }
261 } 262 }
262 263
263 // Remove the old storage item and set the new (if there is one). 264 // Remove the old storage item and set the new (if there is one).
264 ViewStorage* view_storage = ViewStorage::GetInstance(); 265 ViewStorage* view_storage = ViewStorage::GetInstance();
265 if (view_storage->RetrieveView(anchor_view_storage_id_)) 266 if (view_storage->RetrieveView(anchor_view_storage_id_))
266 view_storage->RemoveView(anchor_view_storage_id_); 267 view_storage->RemoveView(anchor_view_storage_id_);
267 if (anchor_view) 268 if (anchor_view)
268 view_storage->StoreView(anchor_view_storage_id_, anchor_view); 269 view_storage->StoreView(anchor_view_storage_id_, anchor_view);
269 270
270 // Do not update anchoring for NULL views; this could indicate that our 271 // 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 272 // 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 273 // 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.) 274 // to update the bounds when |anchor_view| is NULL, the bubble won't move.)
274 if (anchor_view && GetWidget()) 275 if (anchor_view && GetWidget())
275 OnAnchorBoundsChanged(); 276 OnAnchorBoundsChanged();
276 } 277 }
277 278
278 void BubbleDelegateView::SetAnchorRect(const gfx::Rect& rect) { 279 void BubbleDialogDelegateView::SetAnchorRect(const gfx::Rect& rect) {
279 anchor_rect_ = rect; 280 anchor_rect_ = rect;
280 if (GetWidget()) 281 if (GetWidget())
281 OnAnchorBoundsChanged(); 282 OnAnchorBoundsChanged();
282 } 283 }
283 284
284 void BubbleDelegateView::SizeToContents() { 285 void BubbleDialogDelegateView::SizeToContents() {
285 GetWidget()->SetBounds(GetBubbleBounds()); 286 GetWidget()->SetBounds(GetBubbleBounds());
286 } 287 }
287 288
288 BubbleFrameView* BubbleDelegateView::GetBubbleFrameView() const { 289 BubbleFrameView* BubbleDialogDelegateView::GetBubbleFrameView() const {
289 const NonClientView* view = 290 const NonClientView* view =
290 GetWidget() ? GetWidget()->non_client_view() : NULL; 291 GetWidget() ? GetWidget()->non_client_view() : NULL;
291 return view ? static_cast<BubbleFrameView*>(view->frame_view()) : NULL; 292 return view ? static_cast<BubbleFrameView*>(view->frame_view()) : NULL;
292 } 293 }
293 294
294 gfx::Rect BubbleDelegateView::GetBubbleBounds() { 295 gfx::Rect BubbleDialogDelegateView::GetBubbleBounds() {
295 // The argument rect has its origin at the bubble's arrow anchor point; 296 // The argument rect has its origin at the bubble's arrow anchor point;
296 // its size is the preferred size of the bubble's client view (this view). 297 // its size is the preferred size of the bubble's client view (this view).
297 bool anchor_minimized = anchor_widget() && anchor_widget()->IsMinimized(); 298 bool anchor_minimized = anchor_widget() && anchor_widget()->IsMinimized();
298 return GetBubbleFrameView()->GetUpdatedWindowBounds(GetAnchorRect(), 299 return GetBubbleFrameView()->GetUpdatedWindowBounds(
299 GetPreferredSize(), adjust_if_offscreen_ && !anchor_minimized); 300 GetAnchorRect(), GetWidget()->client_view()->GetPreferredSize(),
301 adjust_if_offscreen_ && !anchor_minimized);
300 } 302 }
301 303
302 const gfx::FontList& BubbleDelegateView::GetTitleFontList() const { 304 const gfx::FontList& BubbleDialogDelegateView::GetTitleFontList() const {
303 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 305 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
304 return rb.GetFontList(ui::ResourceBundle::MediumFont); 306 return rb.GetFontList(ui::ResourceBundle::MediumFont);
305 } 307 }
306 308
307 309 void BubbleDialogDelegateView::UpdateColorsFromTheme(
308 void BubbleDelegateView::UpdateColorsFromTheme(const ui::NativeTheme* theme) { 310 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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698