| OLD | NEW |
| 1 // Copyright 2016 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_dialog_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" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // Linux clips bubble windows that extend outside their parent window bounds. | 76 // Linux clips bubble windows that extend outside their parent window bounds. |
| 77 // Mac never adjusts. | 77 // Mac never adjusts. |
| 78 bubble_delegate->set_adjust_if_offscreen(false); | 78 bubble_delegate->set_adjust_if_offscreen(false); |
| 79 #endif | 79 #endif |
| 80 | 80 |
| 81 bubble_delegate->SizeToContents(); | 81 bubble_delegate->SizeToContents(); |
| 82 bubble_widget->AddObserver(bubble_delegate); | 82 bubble_widget->AddObserver(bubble_delegate); |
| 83 return bubble_widget; | 83 return bubble_widget; |
| 84 } | 84 } |
| 85 | 85 |
| 86 BubbleDialogDelegateView* BubbleDialogDelegateView::AsBubbleDialogDelegate() { |
| 87 return this; |
| 88 } |
| 89 |
| 86 bool BubbleDialogDelegateView::ShouldShowCloseButton() const { | 90 bool BubbleDialogDelegateView::ShouldShowCloseButton() const { |
| 87 return false; | 91 return false; |
| 88 } | 92 } |
| 89 | 93 |
| 90 ClientView* BubbleDialogDelegateView::CreateClientView(Widget* widget) { | 94 ClientView* BubbleDialogDelegateView::CreateClientView(Widget* widget) { |
| 91 DialogClientView* client = new DialogClientView(widget, GetContentsView()); | 95 DialogClientView* client = new DialogClientView(widget, GetContentsView()); |
| 92 client->set_button_row_insets(gfx::Insets()); | 96 client->set_button_row_insets(gfx::Insets()); |
| 93 return client; | 97 return client; |
| 94 } | 98 } |
| 95 | 99 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 205 |
| 202 void BubbleDialogDelegateView::OnAnchorBoundsChanged() { | 206 void BubbleDialogDelegateView::OnAnchorBoundsChanged() { |
| 203 SizeToContents(); | 207 SizeToContents(); |
| 204 } | 208 } |
| 205 | 209 |
| 206 BubbleDialogDelegateView::BubbleDialogDelegateView() | 210 BubbleDialogDelegateView::BubbleDialogDelegateView() |
| 207 : BubbleDialogDelegateView(nullptr, BubbleBorder::TOP_LEFT) {} | 211 : BubbleDialogDelegateView(nullptr, BubbleBorder::TOP_LEFT) {} |
| 208 | 212 |
| 209 BubbleDialogDelegateView::BubbleDialogDelegateView(View* anchor_view, | 213 BubbleDialogDelegateView::BubbleDialogDelegateView(View* anchor_view, |
| 210 BubbleBorder::Arrow arrow) | 214 BubbleBorder::Arrow arrow) |
| 211 : close_on_esc_(true), | 215 : close_on_deactivate_(true), |
| 212 close_on_deactivate_(true), | |
| 213 anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()), | 216 anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()), |
| 214 anchor_widget_(NULL), | 217 anchor_widget_(NULL), |
| 215 arrow_(arrow), | 218 arrow_(arrow), |
| 216 shadow_(BubbleBorder::SMALL_SHADOW), | 219 shadow_(BubbleBorder::SMALL_SHADOW), |
| 217 color_explicitly_set_(false), | 220 color_explicitly_set_(false), |
| 218 margins_(kPanelVertMargin, | 221 margins_(kPanelVertMargin, |
| 219 kPanelHorizMargin, | 222 kPanelHorizMargin, |
| 220 kPanelVertMargin, | 223 kPanelVertMargin, |
| 221 kPanelHorizMargin), | 224 kPanelHorizMargin), |
| 222 accept_events_(true), | 225 accept_events_(true), |
| 223 border_accepts_events_(true), | 226 border_accepts_events_(true), |
| 224 adjust_if_offscreen_(true), | 227 adjust_if_offscreen_(true), |
| 225 parent_window_(NULL), | 228 parent_window_(NULL), |
| 226 close_reason_(CloseReason::UNKNOWN) { | 229 close_reason_(CloseReason::UNKNOWN) { |
| 227 if (anchor_view) | 230 if (anchor_view) |
| 228 SetAnchorView(anchor_view); | 231 SetAnchorView(anchor_view); |
| 229 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | |
| 230 UpdateColorsFromTheme(GetNativeTheme()); | 232 UpdateColorsFromTheme(GetNativeTheme()); |
| 231 } | 233 } |
| 232 | 234 |
| 233 gfx::Rect BubbleDialogDelegateView::GetBubbleBounds() { | 235 gfx::Rect BubbleDialogDelegateView::GetBubbleBounds() { |
| 234 // The argument rect has its origin at the bubble's arrow anchor point; | 236 // 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). | 237 // its size is the preferred size of the bubble's client view (this view). |
| 236 bool anchor_minimized = anchor_widget() && anchor_widget()->IsMinimized(); | 238 bool anchor_minimized = anchor_widget() && anchor_widget()->IsMinimized(); |
| 237 return GetBubbleFrameView()->GetUpdatedWindowBounds( | 239 return GetBubbleFrameView()->GetUpdatedWindowBounds( |
| 238 GetAnchorRect(), GetWidget()->client_view()->GetPreferredSize(), | 240 GetAnchorRect(), GetWidget()->client_view()->GetPreferredSize(), |
| 239 adjust_if_offscreen_ && !anchor_minimized); | 241 adjust_if_offscreen_ && !anchor_minimized); |
| 240 } | 242 } |
| 241 | 243 |
| 242 const gfx::FontList& BubbleDialogDelegateView::GetTitleFontList() const { | 244 const gfx::FontList& BubbleDialogDelegateView::GetTitleFontList() const { |
| 243 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 245 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 244 return rb.GetFontList(ui::ResourceBundle::MediumFont); | 246 return rb.GetFontList(ui::ResourceBundle::MediumFont); |
| 245 } | 247 } |
| 246 | 248 |
| 247 bool BubbleDialogDelegateView::AcceleratorPressed( | |
| 248 const ui::Accelerator& accelerator) { | |
| 249 if (!close_on_esc() || accelerator.key_code() != ui::VKEY_ESCAPE) | |
| 250 return false; | |
| 251 close_reason_ = CloseReason::ESCAPE; | |
| 252 GetWidget()->Close(); | |
| 253 return true; | |
| 254 } | |
| 255 | |
| 256 void BubbleDialogDelegateView::OnNativeThemeChanged( | 249 void BubbleDialogDelegateView::OnNativeThemeChanged( |
| 257 const ui::NativeTheme* theme) { | 250 const ui::NativeTheme* theme) { |
| 258 UpdateColorsFromTheme(theme); | 251 UpdateColorsFromTheme(theme); |
| 259 } | 252 } |
| 260 | 253 |
| 261 void BubbleDialogDelegateView::Init() {} | 254 void BubbleDialogDelegateView::Init() {} |
| 262 | 255 |
| 263 void BubbleDialogDelegateView::SetAnchorView(View* anchor_view) { | 256 void BubbleDialogDelegateView::SetAnchorView(View* anchor_view) { |
| 264 // When the anchor view gets set the associated anchor widget might | 257 // When the anchor view gets set the associated anchor widget might |
| 265 // change as well. | 258 // change as well. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 // http://crbug.com/474622 for details. | 325 // http://crbug.com/474622 for details. |
| 333 if (widget == GetWidget() && visible) { | 326 if (widget == GetWidget() && visible) { |
| 334 ui::AXViewState state; | 327 ui::AXViewState state; |
| 335 GetAccessibleState(&state); | 328 GetAccessibleState(&state); |
| 336 if (state.role == ui::AX_ROLE_ALERT_DIALOG) | 329 if (state.role == ui::AX_ROLE_ALERT_DIALOG) |
| 337 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 330 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
| 338 } | 331 } |
| 339 } | 332 } |
| 340 | 333 |
| 341 } // namespace views | 334 } // namespace views |
| OLD | NEW |