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

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, 9 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
« no previous file with comments | « ui/views/bubble/bubble_dialog_delegate.h ('k') | ui/views/bubble/bubble_frame_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/default_style.h"
10 #include "ui/base/resource/resource_bundle.h" 9 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/color_utils.h" 10 #include "ui/gfx/color_utils.h"
12 #include "ui/gfx/geometry/rect.h" 11 #include "ui/gfx/geometry/rect.h"
13 #include "ui/native_theme/native_theme.h" 12 #include "ui/native_theme/native_theme.h"
14 #include "ui/views/bubble/bubble_frame_view.h" 13 #include "ui/views/bubble/bubble_frame_view.h"
15 #include "ui/views/focus/view_storage.h" 14 #include "ui/views/focus/view_storage.h"
16 #include "ui/views/layout/layout_constants.h" 15 #include "ui/views/layout/layout_constants.h"
17 #include "ui/views/widget/widget.h" 16 #include "ui/views/widget/widget.h"
18 #include "ui/views/widget/widget_observer.h" 17 #include "ui/views/widget/widget_observer.h"
18 #include "ui/views/window/dialog_client_view.h"
19 19
20 #if defined(OS_WIN) 20 #if defined(OS_WIN)
21 #include "ui/base/win/shell.h" 21 #include "ui/base/win/shell.h"
22 #endif 22 #endif
23 23
24 namespace views { 24 namespace views {
25 25
26 namespace { 26 namespace {
27 27
28 // Create a widget to host the bubble. 28 // Create a widget to host the bubble.
29 Widget* CreateBubbleWidget(BubbleDelegateView* bubble) { 29 Widget* CreateBubbleWidget(BubbleDialogDelegateView* bubble) {
30 Widget* bubble_widget = new Widget(); 30 Widget* bubble_widget = new Widget();
31 Widget::InitParams bubble_params(Widget::InitParams::TYPE_BUBBLE); 31 Widget::InitParams bubble_params(Widget::InitParams::TYPE_BUBBLE);
32 bubble_params.delegate = bubble; 32 bubble_params.delegate = bubble;
33 bubble_params.opacity = Widget::InitParams::TRANSLUCENT_WINDOW; 33 bubble_params.opacity = Widget::InitParams::TRANSLUCENT_WINDOW;
34 bubble_params.accept_events = bubble->accept_events(); 34 bubble_params.accept_events = bubble->accept_events();
35 if (bubble->parent_window()) 35 if (bubble->parent_window())
36 bubble_params.parent = bubble->parent_window(); 36 bubble_params.parent = bubble->parent_window();
37 else if (bubble->anchor_widget()) 37 else if (bubble->anchor_widget())
38 bubble_params.parent = bubble->anchor_widget()->GetNativeView(); 38 bubble_params.parent = bubble->anchor_widget()->GetNativeView();
39 bubble_params.activatable = bubble->CanActivate() ? 39 bubble_params.activatable = bubble->CanActivate()
40 Widget::InitParams::ACTIVATABLE_YES : Widget::InitParams::ACTIVATABLE_NO; 40 ? Widget::InitParams::ACTIVATABLE_YES
41 : Widget::InitParams::ACTIVATABLE_NO;
41 bubble->OnBeforeBubbleWidgetInit(&bubble_params, bubble_widget); 42 bubble->OnBeforeBubbleWidgetInit(&bubble_params, bubble_widget);
42 bubble_widget->Init(bubble_params); 43 bubble_widget->Init(bubble_params);
43 if (bubble_params.parent) 44 if (bubble_params.parent)
44 bubble_widget->StackAbove(bubble_params.parent); 45 bubble_widget->StackAbove(bubble_params.parent);
45 return bubble_widget; 46 return bubble_widget;
46 } 47 }
47 48
48 } // namespace 49 } // namespace
49 50
50 // static 51 // static
51 const char BubbleDelegateView::kViewClassName[] = "BubbleDelegateView"; 52 const char BubbleDialogDelegateView::kViewClassName[] =
53 "BubbleDialogDelegateView";
52 54
53 BubbleDelegateView::BubbleDelegateView() 55 BubbleDialogDelegateView::~BubbleDialogDelegateView() {
54 : BubbleDelegateView(nullptr, BubbleBorder::TOP_LEFT) {}
55
56 BubbleDelegateView::BubbleDelegateView(View* anchor_view,
57 BubbleBorder::Arrow arrow)
58 : close_on_esc_(true),
59 close_on_deactivate_(true),
60 anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()),
61 anchor_widget_(NULL),
62 arrow_(arrow),
63 shadow_(BubbleBorder::SMALL_SHADOW),
64 color_explicitly_set_(false),
65 margins_(kPanelVertMargin,
66 kPanelHorizMargin,
67 kPanelVertMargin,
68 kPanelHorizMargin),
69 accept_events_(true),
70 border_accepts_events_(true),
71 adjust_if_offscreen_(true),
72 parent_window_(NULL),
73 close_reason_(CloseReason::UNKNOWN) {
74 if (anchor_view)
75 SetAnchorView(anchor_view);
76 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
77 UpdateColorsFromTheme(GetNativeTheme());
78 }
79
80 BubbleDelegateView::~BubbleDelegateView() {
81 if (GetWidget()) 56 if (GetWidget())
82 GetWidget()->RemoveObserver(this); 57 GetWidget()->RemoveObserver(this);
83 SetLayoutManager(NULL); 58 SetLayoutManager(NULL);
84 SetAnchorView(NULL); 59 SetAnchorView(NULL);
85 } 60 }
86 61
87 // static 62 // static
88 Widget* BubbleDelegateView::CreateBubble(BubbleDelegateView* bubble_delegate) { 63 Widget* BubbleDialogDelegateView::CreateBubble(
64 BubbleDialogDelegateView* bubble_delegate) {
89 bubble_delegate->Init(); 65 bubble_delegate->Init();
90 // 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.
91 bubble_delegate->SetAnchorView(bubble_delegate->GetAnchorView()); 67 bubble_delegate->SetAnchorView(bubble_delegate->GetAnchorView());
92 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate); 68 Widget* bubble_widget = CreateBubbleWidget(bubble_delegate);
93 69
94 #if defined(OS_WIN) 70 #if defined(OS_WIN)
95 // 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
96 // 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
97 // 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.
98 bubble_delegate->set_adjust_if_offscreen(ui::win::IsAeroGlassEnabled()); 74 bubble_delegate->set_adjust_if_offscreen(ui::win::IsAeroGlassEnabled());
99 #elif (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX) 75 #elif (defined(OS_LINUX) && !defined(OS_CHROMEOS)) || defined(OS_MACOSX)
100 // Linux clips bubble windows that extend outside their parent window bounds. 76 // Linux clips bubble windows that extend outside their parent window bounds.
101 // Mac never adjusts. 77 // Mac never adjusts.
102 bubble_delegate->set_adjust_if_offscreen(false); 78 bubble_delegate->set_adjust_if_offscreen(false);
103 #endif 79 #endif
104 80
105 bubble_delegate->SizeToContents(); 81 bubble_delegate->SizeToContents();
106 bubble_widget->AddObserver(bubble_delegate); 82 bubble_widget->AddObserver(bubble_delegate);
107 return bubble_widget; 83 return bubble_widget;
108 } 84 }
109 85
110 BubbleDelegateView* BubbleDelegateView::AsBubbleDelegate() { 86 bool BubbleDialogDelegateView::ShouldShowCloseButton() const {
111 return this;
112 }
113
114 bool BubbleDelegateView::ShouldShowCloseButton() const {
115 return false; 87 return false;
116 } 88 }
117 89
118 View* BubbleDelegateView::GetContentsView() { 90 ClientView* BubbleDialogDelegateView::CreateClientView(Widget* widget) {
119 return this; 91 DialogClientView* client = new DialogClientView(widget, GetContentsView());
92 client->set_button_row_insets(gfx::Insets());
93 return client;
120 } 94 }
121 95
122 NonClientFrameView* BubbleDelegateView::CreateNonClientFrameView( 96 NonClientFrameView* BubbleDialogDelegateView::CreateNonClientFrameView(
123 Widget* widget) { 97 Widget* widget) {
124 BubbleFrameView* frame = new BubbleFrameView( 98 BubbleFrameView* frame = new BubbleFrameView(
125 gfx::Insets(kPanelVertMargin, kPanelHorizMargin, 0, kPanelHorizMargin), 99 gfx::Insets(kPanelVertMargin, kPanelHorizMargin, 0, kPanelHorizMargin),
126 margins()); 100 margins());
127 // Note: In CreateBubble, the call to SizeToContents() will cause 101 // Note: In CreateBubble, the call to SizeToContents() will cause
128 // the relayout that this call requires. 102 // the relayout that this call requires.
129 frame->SetTitleFontList(GetTitleFontList()); 103 frame->SetTitleFontList(GetTitleFontList());
130 frame->SetFootnoteView(CreateFootnoteView()); 104 frame->SetFootnoteView(CreateFootnoteView());
131 105
132 BubbleBorder::Arrow adjusted_arrow = arrow(); 106 BubbleBorder::Arrow adjusted_arrow = arrow();
133 if (base::i18n::IsRTL()) 107 if (base::i18n::IsRTL())
134 adjusted_arrow = BubbleBorder::horizontal_mirror(adjusted_arrow); 108 adjusted_arrow = BubbleBorder::horizontal_mirror(adjusted_arrow);
135 frame->SetBubbleBorder(scoped_ptr<BubbleBorder>( 109 frame->SetBubbleBorder(scoped_ptr<BubbleBorder>(
136 new BubbleBorder(adjusted_arrow, shadow(), color()))); 110 new BubbleBorder(adjusted_arrow, shadow(), color())));
137 return frame; 111 return frame;
138 } 112 }
139 113
140 void BubbleDelegateView::GetAccessibleState(ui::AXViewState* state) { 114 void BubbleDialogDelegateView::GetAccessibleState(ui::AXViewState* state) {
141 state->role = ui::AX_ROLE_DIALOG; 115 state->role = ui::AX_ROLE_DIALOG;
142 } 116 }
143 117
144 const char* BubbleDelegateView::GetClassName() const { 118 const char* BubbleDialogDelegateView::GetClassName() const {
145 return kViewClassName; 119 return kViewClassName;
146 } 120 }
147 121
148 void BubbleDelegateView::OnWidgetClosing(Widget* widget) { 122 void BubbleDialogDelegateView::OnWidgetClosing(Widget* widget) {
149 DCHECK(GetBubbleFrameView()); 123 DCHECK(GetBubbleFrameView());
150 if (widget == GetWidget() && close_reason_ == CloseReason::UNKNOWN && 124 if (widget == GetWidget() && close_reason_ == CloseReason::UNKNOWN &&
151 GetBubbleFrameView()->close_button_clicked()) { 125 GetBubbleFrameView()->close_button_clicked()) {
152 close_reason_ = CloseReason::CLOSE_BUTTON; 126 close_reason_ = CloseReason::CLOSE_BUTTON;
153 } 127 }
154 } 128 }
155 129
156 void BubbleDelegateView::OnWidgetDestroying(Widget* widget) { 130 void BubbleDialogDelegateView::OnWidgetDestroying(Widget* widget) {
157 if (anchor_widget() == widget) 131 if (anchor_widget() == widget)
158 SetAnchorView(NULL); 132 SetAnchorView(NULL);
159 } 133 }
160 134
161 void BubbleDelegateView::OnWidgetVisibilityChanging(Widget* widget, 135 void BubbleDialogDelegateView::OnWidgetVisibilityChanging(Widget* widget,
162 bool visible) { 136 bool visible) {
163 #if defined(OS_WIN) 137 #if defined(OS_WIN)
164 // 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.
165 // Please see the comment on the OnWidgetVisibilityChanging function. On 139 // Please see the comment on the OnWidgetVisibilityChanging function. On
166 // 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.
167 HandleVisibilityChanged(widget, visible); 141 HandleVisibilityChanged(widget, visible);
168 #endif 142 #endif
169 } 143 }
170 144
171 void BubbleDelegateView::OnWidgetVisibilityChanged(Widget* widget, 145 void BubbleDialogDelegateView::OnWidgetVisibilityChanged(Widget* widget,
172 bool visible) { 146 bool visible) {
173 #if !defined(OS_WIN) 147 #if !defined(OS_WIN)
174 HandleVisibilityChanged(widget, visible); 148 HandleVisibilityChanged(widget, visible);
175 #endif 149 #endif
176 } 150 }
177 151
178 void BubbleDelegateView::OnWidgetActivationChanged(Widget* widget, 152 void BubbleDialogDelegateView::OnWidgetActivationChanged(Widget* widget,
179 bool active) { 153 bool active) {
180 if (close_on_deactivate() && widget == GetWidget() && !active) { 154 if (close_on_deactivate() && widget == GetWidget() && !active) {
181 if (close_reason_ == CloseReason::UNKNOWN) 155 if (close_reason_ == CloseReason::UNKNOWN)
182 close_reason_ = CloseReason::DEACTIVATION; 156 close_reason_ = CloseReason::DEACTIVATION;
183 GetWidget()->Close(); 157 GetWidget()->Close();
184 } 158 }
185 } 159 }
186 160
187 void BubbleDelegateView::OnWidgetBoundsChanged(Widget* widget, 161 void BubbleDialogDelegateView::OnWidgetBoundsChanged(
188 const gfx::Rect& new_bounds) { 162 Widget* widget,
163 const gfx::Rect& new_bounds) {
189 if (GetBubbleFrameView() && anchor_widget() == widget) 164 if (GetBubbleFrameView() && anchor_widget() == widget)
190 SizeToContents(); 165 SizeToContents();
191 } 166 }
192 167
193 View* BubbleDelegateView::GetAnchorView() const { 168 View* BubbleDialogDelegateView::GetAnchorView() const {
194 return ViewStorage::GetInstance()->RetrieveView(anchor_view_storage_id_); 169 return ViewStorage::GetInstance()->RetrieveView(anchor_view_storage_id_);
195 } 170 }
196 171
197 gfx::Rect BubbleDelegateView::GetAnchorRect() const { 172 gfx::Rect BubbleDialogDelegateView::GetAnchorRect() const {
198 if (!GetAnchorView()) 173 if (!GetAnchorView())
199 return anchor_rect_; 174 return anchor_rect_;
200 175
201 anchor_rect_ = GetAnchorView()->GetBoundsInScreen(); 176 anchor_rect_ = GetAnchorView()->GetBoundsInScreen();
202 anchor_rect_.Inset(anchor_view_insets_); 177 anchor_rect_.Inset(anchor_view_insets_);
203 return anchor_rect_; 178 return anchor_rect_;
204 } 179 }
205 180
206 void BubbleDelegateView::OnBeforeBubbleWidgetInit(Widget::InitParams* params, 181 void BubbleDialogDelegateView::OnBeforeBubbleWidgetInit(
207 Widget* widget) const { 182 Widget::InitParams* params,
208 } 183 Widget* widget) const {}
209 184
210 scoped_ptr<View> BubbleDelegateView::CreateFootnoteView() { 185 void BubbleDialogDelegateView::UseCompactMargins() {
211 return nullptr;
212 }
213
214 void BubbleDelegateView::UseCompactMargins() {
215 const int kCompactMargin = 6; 186 const int kCompactMargin = 6;
216 margins_.Set(kCompactMargin, kCompactMargin, kCompactMargin, kCompactMargin); 187 margins_.Set(kCompactMargin, kCompactMargin, kCompactMargin, kCompactMargin);
217 } 188 }
218 189
219 void BubbleDelegateView::SetAlignment(BubbleBorder::BubbleAlignment alignment) { 190 void BubbleDialogDelegateView::SetAlignment(
191 BubbleBorder::BubbleAlignment alignment) {
220 GetBubbleFrameView()->bubble_border()->set_alignment(alignment); 192 GetBubbleFrameView()->bubble_border()->set_alignment(alignment);
221 SizeToContents(); 193 SizeToContents();
222 } 194 }
223 195
224 void BubbleDelegateView::SetArrowPaintType( 196 void BubbleDialogDelegateView::SetArrowPaintType(
225 BubbleBorder::ArrowPaintType paint_type) { 197 BubbleBorder::ArrowPaintType paint_type) {
226 GetBubbleFrameView()->bubble_border()->set_paint_arrow(paint_type); 198 GetBubbleFrameView()->bubble_border()->set_paint_arrow(paint_type);
227 SizeToContents(); 199 SizeToContents();
228 } 200 }
229 201
230 void BubbleDelegateView::OnAnchorBoundsChanged() { 202 void BubbleDialogDelegateView::OnAnchorBoundsChanged() {
231 SizeToContents(); 203 SizeToContents();
232 } 204 }
233 205
234 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(
235 const ui::Accelerator& accelerator) { 248 const ui::Accelerator& accelerator) {
236 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) 249 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE)
237 return false; 250 return false;
238 close_reason_ = CloseReason::ESCAPE; 251 close_reason_ = CloseReason::ESCAPE;
239 GetWidget()->Close(); 252 GetWidget()->Close();
240 return true; 253 return true;
241 } 254 }
242 255
243 void BubbleDelegateView::OnNativeThemeChanged(const ui::NativeTheme* theme) { 256 void BubbleDialogDelegateView::OnNativeThemeChanged(
257 const ui::NativeTheme* theme) {
244 UpdateColorsFromTheme(theme); 258 UpdateColorsFromTheme(theme);
245 } 259 }
246 260
247 void BubbleDelegateView::Init() {} 261 void BubbleDialogDelegateView::Init() {}
248 262
249 void BubbleDelegateView::SetAnchorView(View* anchor_view) { 263 void BubbleDialogDelegateView::SetAnchorView(View* anchor_view) {
250 // When the anchor view gets set the associated anchor widget might 264 // When the anchor view gets set the associated anchor widget might
251 // change as well. 265 // change as well.
252 if (!anchor_view || anchor_widget() != anchor_view->GetWidget()) { 266 if (!anchor_view || anchor_widget() != anchor_view->GetWidget()) {
253 if (anchor_widget()) { 267 if (anchor_widget()) {
254 anchor_widget_->RemoveObserver(this); 268 anchor_widget_->RemoveObserver(this);
255 anchor_widget_ = NULL; 269 anchor_widget_ = NULL;
256 } 270 }
257 if (anchor_view) { 271 if (anchor_view) {
258 anchor_widget_ = anchor_view->GetWidget(); 272 anchor_widget_ = anchor_view->GetWidget();
259 if (anchor_widget_) 273 if (anchor_widget_)
260 anchor_widget_->AddObserver(this); 274 anchor_widget_->AddObserver(this);
261 } 275 }
262 } 276 }
263 277
264 // 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).
265 ViewStorage* view_storage = ViewStorage::GetInstance(); 279 ViewStorage* view_storage = ViewStorage::GetInstance();
266 if (view_storage->RetrieveView(anchor_view_storage_id_)) 280 if (view_storage->RetrieveView(anchor_view_storage_id_))
267 view_storage->RemoveView(anchor_view_storage_id_); 281 view_storage->RemoveView(anchor_view_storage_id_);
268 if (anchor_view) 282 if (anchor_view)
269 view_storage->StoreView(anchor_view_storage_id_, anchor_view); 283 view_storage->StoreView(anchor_view_storage_id_, anchor_view);
270 284
271 // 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
272 // 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
273 // 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
274 // 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.)
275 if (anchor_view && GetWidget()) 289 if (anchor_view && GetWidget())
276 OnAnchorBoundsChanged(); 290 OnAnchorBoundsChanged();
277 } 291 }
278 292
279 void BubbleDelegateView::SetAnchorRect(const gfx::Rect& rect) { 293 void BubbleDialogDelegateView::SetAnchorRect(const gfx::Rect& rect) {
280 anchor_rect_ = rect; 294 anchor_rect_ = rect;
281 if (GetWidget()) 295 if (GetWidget())
282 OnAnchorBoundsChanged(); 296 OnAnchorBoundsChanged();
283 } 297 }
284 298
285 void BubbleDelegateView::SizeToContents() { 299 void BubbleDialogDelegateView::SizeToContents() {
286 GetWidget()->SetBounds(GetBubbleBounds()); 300 GetWidget()->SetBounds(GetBubbleBounds());
287 } 301 }
288 302
289 BubbleFrameView* BubbleDelegateView::GetBubbleFrameView() const { 303 BubbleFrameView* BubbleDialogDelegateView::GetBubbleFrameView() const {
290 const NonClientView* view = 304 const NonClientView* view =
291 GetWidget() ? GetWidget()->non_client_view() : NULL; 305 GetWidget() ? GetWidget()->non_client_view() : NULL;
292 return view ? static_cast<BubbleFrameView*>(view->frame_view()) : NULL; 306 return view ? static_cast<BubbleFrameView*>(view->frame_view()) : NULL;
293 } 307 }
294 308
295 gfx::Rect BubbleDelegateView::GetBubbleBounds() { 309 void BubbleDialogDelegateView::UpdateColorsFromTheme(
296 // The argument rect has its origin at the bubble's arrow anchor point; 310 const ui::NativeTheme* theme) {
297 // its size is the preferred size of the bubble's client view (this view).
298 bool anchor_minimized = anchor_widget() && anchor_widget()->IsMinimized();
299 return GetBubbleFrameView()->GetUpdatedWindowBounds(GetAnchorRect(),
300 GetPreferredSize(), adjust_if_offscreen_ && !anchor_minimized);
301 }
302
303 const gfx::FontList& BubbleDelegateView::GetTitleFontList() const {
304 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
305 return rb.GetFontListWithDelta(ui::kTitleFontSizeDelta);
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
OLDNEW
« no previous file with comments | « ui/views/bubble/bubble_dialog_delegate.h ('k') | ui/views/bubble/bubble_frame_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698