| 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_node_data.h" | 8 #include "ui/accessibility/ax_node_data.h" |
| 9 #include "ui/base/default_style.h" |
| 9 #include "ui/base/material_design/material_design_controller.h" | 10 #include "ui/base/material_design/material_design_controller.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/gfx/color_utils.h" | 12 #include "ui/gfx/color_utils.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
| 13 #include "ui/native_theme/native_theme.h" | 14 #include "ui/native_theme/native_theme.h" |
| 14 #include "ui/views/bubble/bubble_frame_view.h" | 15 #include "ui/views/bubble/bubble_frame_view.h" |
| 15 #include "ui/views/focus/view_storage.h" | 16 #include "ui/views/focus/view_storage.h" |
| 16 #include "ui/views/layout/layout_constants.h" | 17 #include "ui/views/layout/layout_constants.h" |
| 17 #include "ui/views/style/platform_style.h" | 18 #include "ui/views/style/platform_style.h" |
| 19 #include "ui/views/views_delegate.h" |
| 18 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 19 #include "ui/views/widget/widget_observer.h" | 21 #include "ui/views/widget/widget_observer.h" |
| 20 #include "ui/views/window/dialog_client_view.h" | 22 #include "ui/views/window/dialog_client_view.h" |
| 21 | 23 |
| 22 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 23 #include "ui/base/win/shell.h" | 25 #include "ui/base/win/shell.h" |
| 24 #endif | 26 #endif |
| 25 | 27 |
| 26 namespace views { | 28 namespace views { |
| 27 | 29 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 97 |
| 96 ClientView* BubbleDialogDelegateView::CreateClientView(Widget* widget) { | 98 ClientView* BubbleDialogDelegateView::CreateClientView(Widget* widget) { |
| 97 DialogClientView* client = new DialogClientView(widget, GetContentsView()); | 99 DialogClientView* client = new DialogClientView(widget, GetContentsView()); |
| 98 client->set_button_row_insets(gfx::Insets()); | 100 client->set_button_row_insets(gfx::Insets()); |
| 99 widget->non_client_view()->set_mirror_client_in_rtl(mirror_arrow_in_rtl_); | 101 widget->non_client_view()->set_mirror_client_in_rtl(mirror_arrow_in_rtl_); |
| 100 return client; | 102 return client; |
| 101 } | 103 } |
| 102 | 104 |
| 103 NonClientFrameView* BubbleDialogDelegateView::CreateNonClientFrameView( | 105 NonClientFrameView* BubbleDialogDelegateView::CreateNonClientFrameView( |
| 104 Widget* widget) { | 106 Widget* widget) { |
| 107 ViewsDelegate* views_delegate = ViewsDelegate::GetInstance(); |
| 105 BubbleFrameView* frame = new BubbleFrameView( | 108 BubbleFrameView* frame = new BubbleFrameView( |
| 106 gfx::Insets(kPanelVertMargin, kPanelHorizMargin, 0, kPanelHorizMargin), | 109 views_delegate ? views_delegate->GetDialogFrameViewInsets() |
| 110 : gfx::Insets(kPanelVertMargin, kPanelHorizMargin, 0, |
| 111 kPanelHorizMargin), |
| 107 margins()); | 112 margins()); |
| 108 // Note: In CreateBubble, the call to SizeToContents() will cause | 113 // Note: In CreateBubble, the call to SizeToContents() will cause |
| 109 // the relayout that this call requires. | 114 // the relayout that this call requires. |
| 110 frame->SetTitleFontList(GetTitleFontList()); | 115 frame->SetTitleFontList(GetTitleFontList()); |
| 111 frame->SetFootnoteView(CreateFootnoteView()); | 116 frame->SetFootnoteView(CreateFootnoteView()); |
| 112 | 117 |
| 113 BubbleBorder::Arrow adjusted_arrow = arrow(); | 118 BubbleBorder::Arrow adjusted_arrow = arrow(); |
| 114 if (base::i18n::IsRTL() && mirror_arrow_in_rtl_) | 119 if (base::i18n::IsRTL() && mirror_arrow_in_rtl_) |
| 115 adjusted_arrow = BubbleBorder::horizontal_mirror(adjusted_arrow); | 120 adjusted_arrow = BubbleBorder::horizontal_mirror(adjusted_arrow); |
| 116 frame->SetBubbleBorder(std::unique_ptr<BubbleBorder>( | 121 frame->SetBubbleBorder(std::unique_ptr<BubbleBorder>( |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 | 210 |
| 206 BubbleDialogDelegateView::BubbleDialogDelegateView(View* anchor_view, | 211 BubbleDialogDelegateView::BubbleDialogDelegateView(View* anchor_view, |
| 207 BubbleBorder::Arrow arrow) | 212 BubbleBorder::Arrow arrow) |
| 208 : close_on_deactivate_(true), | 213 : close_on_deactivate_(true), |
| 209 anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()), | 214 anchor_view_storage_id_(ViewStorage::GetInstance()->CreateStorageID()), |
| 210 anchor_widget_(NULL), | 215 anchor_widget_(NULL), |
| 211 arrow_(arrow), | 216 arrow_(arrow), |
| 212 mirror_arrow_in_rtl_(PlatformStyle::kMirrorBubbleArrowInRTLByDefault), | 217 mirror_arrow_in_rtl_(PlatformStyle::kMirrorBubbleArrowInRTLByDefault), |
| 213 shadow_(BubbleBorder::SMALL_SHADOW), | 218 shadow_(BubbleBorder::SMALL_SHADOW), |
| 214 color_explicitly_set_(false), | 219 color_explicitly_set_(false), |
| 215 margins_(kPanelVertMargin, | |
| 216 kPanelHorizMargin, | |
| 217 kPanelVertMargin, | |
| 218 kPanelHorizMargin), | |
| 219 accept_events_(true), | 220 accept_events_(true), |
| 220 adjust_if_offscreen_(true), | 221 adjust_if_offscreen_(true), |
| 221 parent_window_(NULL) { | 222 parent_window_(NULL) { |
| 223 margins_ = ViewsDelegate::GetInstance() |
| 224 ? ViewsDelegate::GetInstance()->GetBubbleDialogMargins() |
| 225 : gfx::Insets(kPanelVertMargin, kPanelHorizMargin, |
| 226 kPanelVertMargin, kPanelHorizMargin); |
| 222 if (anchor_view) | 227 if (anchor_view) |
| 223 SetAnchorView(anchor_view); | 228 SetAnchorView(anchor_view); |
| 224 UpdateColorsFromTheme(GetNativeTheme()); | 229 UpdateColorsFromTheme(GetNativeTheme()); |
| 225 } | 230 } |
| 226 | 231 |
| 227 gfx::Rect BubbleDialogDelegateView::GetBubbleBounds() { | 232 gfx::Rect BubbleDialogDelegateView::GetBubbleBounds() { |
| 228 // The argument rect has its origin at the bubble's arrow anchor point; | 233 // The argument rect has its origin at the bubble's arrow anchor point; |
| 229 // its size is the preferred size of the bubble's client view (this view). | 234 // its size is the preferred size of the bubble's client view (this view). |
| 230 bool anchor_minimized = anchor_widget() && anchor_widget()->IsMinimized(); | 235 bool anchor_minimized = anchor_widget() && anchor_widget()->IsMinimized(); |
| 231 return GetBubbleFrameView()->GetUpdatedWindowBounds( | 236 return GetBubbleFrameView()->GetUpdatedWindowBounds( |
| 232 GetAnchorRect(), GetWidget()->client_view()->GetPreferredSize(), | 237 GetAnchorRect(), GetWidget()->client_view()->GetPreferredSize(), |
| 233 adjust_if_offscreen_ && !anchor_minimized); | 238 adjust_if_offscreen_ && !anchor_minimized); |
| 234 } | 239 } |
| 235 | 240 |
| 236 const gfx::FontList& BubbleDialogDelegateView::GetTitleFontList() const { | 241 const gfx::FontList& BubbleDialogDelegateView::GetTitleFontList() const { |
| 237 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 242 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 243 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) |
| 244 return rb.GetFontListWithDelta(ui::kTitleFontSizeDelta); |
| 238 return rb.GetFontList(ui::ResourceBundle::MediumFont); | 245 return rb.GetFontList(ui::ResourceBundle::MediumFont); |
| 239 } | 246 } |
| 240 | 247 |
| 241 void BubbleDialogDelegateView::OnNativeThemeChanged( | 248 void BubbleDialogDelegateView::OnNativeThemeChanged( |
| 242 const ui::NativeTheme* theme) { | 249 const ui::NativeTheme* theme) { |
| 243 UpdateColorsFromTheme(theme); | 250 UpdateColorsFromTheme(theme); |
| 244 } | 251 } |
| 245 | 252 |
| 246 void BubbleDialogDelegateView::Init() {} | 253 void BubbleDialogDelegateView::Init() {} |
| 247 | 254 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 // http://crbug.com/474622 for details. | 326 // http://crbug.com/474622 for details. |
| 320 if (widget == GetWidget() && visible) { | 327 if (widget == GetWidget() && visible) { |
| 321 ui::AXNodeData node_data; | 328 ui::AXNodeData node_data; |
| 322 GetAccessibleNodeData(&node_data); | 329 GetAccessibleNodeData(&node_data); |
| 323 if (node_data.role == ui::AX_ROLE_ALERT_DIALOG) | 330 if (node_data.role == ui::AX_ROLE_ALERT_DIALOG) |
| 324 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 331 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
| 325 } | 332 } |
| 326 } | 333 } |
| 327 | 334 |
| 328 } // namespace views | 335 } // namespace views |
| OLD | NEW |