Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_frame_view.h" | 5 #include "ui/views/bubble/bubble_frame_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "ui/base/default_style.h" | 11 #include "ui/base/default_style.h" |
| 12 #include "ui/base/hit_test.h" | 12 #include "ui/base/hit_test.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/material_design/material_design_controller.h" | 14 #include "ui/base/material_design/material_design_controller.h" |
| 15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/compositor/paint_context.h" | 16 #include "ui/compositor/paint_context.h" |
| 17 #include "ui/compositor/paint_recorder.h" | 17 #include "ui/compositor/paint_recorder.h" |
| 18 #include "ui/display/display.h" | 18 #include "ui/display/display.h" |
| 19 #include "ui/display/screen.h" | 19 #include "ui/display/screen.h" |
| 20 #include "ui/gfx/geometry/vector2d.h" | 20 #include "ui/gfx/geometry/vector2d.h" |
| 21 #include "ui/gfx/path.h" | 21 #include "ui/gfx/path.h" |
| 22 #include "ui/gfx/skia_util.h" | 22 #include "ui/gfx/skia_util.h" |
| 23 #include "ui/gfx/vector_icons_public.h" | 23 #include "ui/gfx/vector_icons_public.h" |
| 24 #include "ui/native_theme/native_theme.h" | 24 #include "ui/native_theme/native_theme.h" |
| 25 #include "ui/resources/grit/ui_resources.h" | 25 #include "ui/resources/grit/ui_resources.h" |
| 26 #include "ui/strings/grit/ui_strings.h" | 26 #include "ui/strings/grit/ui_strings.h" |
| 27 #include "ui/views/bubble/bubble_border.h" | 27 #include "ui/views/bubble/bubble_border.h" |
| 28 #include "ui/views/controls/button/label_button.h" | |
| 29 #include "ui/views/controls/button/vector_icon_button.h" | 28 #include "ui/views/controls/button/vector_icon_button.h" |
| 30 #include "ui/views/controls/image_view.h" | 29 #include "ui/views/controls/image_view.h" |
| 30 #include "ui/views/controls/label.h" | |
| 31 #include "ui/views/layout/box_layout.h" | 31 #include "ui/views/layout/box_layout.h" |
| 32 #include "ui/views/layout/layout_constants.h" | 32 #include "ui/views/layout/layout_constants.h" |
| 33 #include "ui/views/resources/grit/views_resources.h" | 33 #include "ui/views/resources/grit/views_resources.h" |
| 34 #include "ui/views/widget/widget.h" | 34 #include "ui/views/widget/widget.h" |
| 35 #include "ui/views/widget/widget_delegate.h" | 35 #include "ui/views/widget/widget_delegate.h" |
| 36 #include "ui/views/window/client_view.h" | 36 #include "ui/views/window/client_view.h" |
| 37 | 37 |
| 38 namespace views { | 38 namespace views { |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 // Background color of the footnote view. | 42 // Background color of the footnote view. |
| 43 const SkColor kFootnoteBackgroundColor = SkColorSetRGB(245, 245, 245); | 43 const SkColor kFootnoteBackgroundColor = SkColorSetRGB(245, 245, 245); |
| 44 | 44 |
| 45 // Color of the top border of the footnote. | 45 // Color of the top border of the footnote. |
| 46 const SkColor kFootnoteBorderColor = SkColorSetRGB(229, 229, 229); | 46 const SkColor kFootnoteBorderColor = SkColorSetRGB(229, 229, 229); |
| 47 | 47 |
| 48 constexpr int kClosePaddingRight = 7; | 48 constexpr int kClosePaddingRight = 7; |
| 49 constexpr int kClosePaddingTop = 6; | 49 constexpr int kClosePaddingTop = 7; |
| 50 | 50 |
| 51 // The MD spec states that the center of the "x" should be 16x16 from the top | 51 // The MD spec states that the center of the "x" should be 16x16 from the top |
| 52 // right of the dialog. | 52 // right of the dialog. |
| 53 constexpr int kClosePaddingRightMd = 4; | 53 constexpr int kClosePaddingRightMd = 4; |
| 54 constexpr int kClosePaddingTopMd = 5; | 54 constexpr int kClosePaddingTopMd = 5; |
| 55 | 55 |
| 56 // Get the |vertical| or horizontal amount that |available_bounds| overflows | 56 // Get the |vertical| or horizontal amount that |available_bounds| overflows |
| 57 // |window_bounds|. | 57 // |window_bounds|. |
| 58 int GetOffScreenLength(const gfx::Rect& available_bounds, | 58 int GetOffScreenLength(const gfx::Rect& available_bounds, |
| 59 const gfx::Rect& window_bounds, | 59 const gfx::Rect& window_bounds, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 // the HTCLOSE result from NonClientHitTest(). | 109 // the HTCLOSE result from NonClientHitTest(). |
| 110 close_->SetTooltipText(base::string16()); | 110 close_->SetTooltipText(base::string16()); |
| 111 #endif | 111 #endif |
| 112 AddChildView(close_); | 112 AddChildView(close_); |
| 113 } | 113 } |
| 114 | 114 |
| 115 BubbleFrameView::~BubbleFrameView() {} | 115 BubbleFrameView::~BubbleFrameView() {} |
| 116 | 116 |
| 117 // static | 117 // static |
| 118 Button* BubbleFrameView::CreateCloseButton(VectorIconButtonDelegate* delegate) { | 118 Button* BubbleFrameView::CreateCloseButton(VectorIconButtonDelegate* delegate) { |
| 119 Button* close_button = nullptr; | 119 ImageButton* close_button = nullptr; |
| 120 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | 120 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
| 121 VectorIconButton* close = new VectorIconButton(delegate); | 121 VectorIconButton* close = new VectorIconButton(delegate); |
| 122 close->SetIcon(gfx::VectorIconId::BAR_CLOSE); | 122 close->SetIcon(gfx::VectorIconId::BAR_CLOSE); |
| 123 close->SetSize(close->GetPreferredSize()); | |
| 124 close_button = close; | 123 close_button = close; |
| 125 } else { | 124 } else { |
| 126 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 125 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 127 LabelButton* close = new LabelButton(delegate, base::string16()); | 126 close_button = new ImageButton(delegate); |
| 128 close->SetImage(CustomButton::STATE_NORMAL, | 127 close_button->SetImage(CustomButton::STATE_NORMAL, |
| 129 *rb.GetImageNamed(IDR_CLOSE_DIALOG).ToImageSkia()); | 128 *rb->GetImageNamed(IDR_CLOSE_DIALOG).ToImageSkia()); |
| 130 close->SetImage(CustomButton::STATE_HOVERED, | 129 close_button->SetImage( |
| 131 *rb.GetImageNamed(IDR_CLOSE_DIALOG_H).ToImageSkia()); | 130 CustomButton::STATE_HOVERED, |
| 132 close->SetImage(CustomButton::STATE_PRESSED, | 131 *rb->GetImageNamed(IDR_CLOSE_DIALOG_H).ToImageSkia()); |
| 133 *rb.GetImageNamed(IDR_CLOSE_DIALOG_P).ToImageSkia()); | 132 close_button->SetImage( |
| 134 close->SetBorder(nullptr); | 133 CustomButton::STATE_PRESSED, |
| 135 close->SetSize(close->GetPreferredSize()); | 134 *rb->GetImageNamed(IDR_CLOSE_DIALOG_P).ToImageSkia()); |
| 136 close_button = close; | |
| 137 } | 135 } |
| 138 close_button->SetTooltipText(l10n_util::GetStringUTF16(IDS_APP_CLOSE)); | 136 close_button->SetTooltipText(l10n_util::GetStringUTF16(IDS_APP_CLOSE)); |
| 137 close_button->SizeToPreferredSize(); | |
| 139 return close_button; | 138 return close_button; |
| 140 } | 139 } |
| 141 | 140 |
| 142 gfx::Rect BubbleFrameView::GetBoundsForClientView() const { | 141 gfx::Rect BubbleFrameView::GetBoundsForClientView() const { |
| 143 gfx::Rect client_bounds = GetContentsBounds(); | 142 gfx::Rect client_bounds = GetContentsBounds(); |
| 144 client_bounds.Inset(GetInsets()); | 143 client_bounds.Inset(GetInsets()); |
| 145 if (footnote_container_) { | 144 if (footnote_container_) { |
| 146 client_bounds.set_height(client_bounds.height() - | 145 client_bounds.set_height(client_bounds.height() - |
| 147 footnote_container_->height()); | 146 footnote_container_->height()); |
| 148 } | 147 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 // preferred size. | 307 // preferred size. |
| 309 return GetPreferredSize(); | 308 return GetPreferredSize(); |
| 310 #endif | 309 #endif |
| 311 } | 310 } |
| 312 | 311 |
| 313 void BubbleFrameView::Layout() { | 312 void BubbleFrameView::Layout() { |
| 314 // The title margins may not be set, but make sure that's only the case when | 313 // The title margins may not be set, but make sure that's only the case when |
| 315 // there's no title. | 314 // there's no title. |
| 316 DCHECK(!title_margins_.IsEmpty() || !title_->visible()); | 315 DCHECK(!title_margins_.IsEmpty() || !title_->visible()); |
| 317 | 316 |
| 318 gfx::Rect bounds(GetContentsBounds()); | 317 const gfx::Rect contents_bounds = GetContentsBounds(); |
| 318 gfx::Rect bounds = contents_bounds; | |
| 319 bounds.Inset(title_margins_); | 319 bounds.Inset(title_margins_); |
| 320 if (bounds.IsEmpty()) | 320 if (bounds.IsEmpty()) |
| 321 return; | 321 return; |
| 322 | 322 |
| 323 // The close button is positioned somewhat closer to the edge of the bubble. | 323 // The close button is positioned somewhat closer to the edge of the bubble. |
| 324 gfx::Point close_position = GetContentsBounds().top_right(); | 324 gfx::Point close_position = contents_bounds.top_right(); |
| 325 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | 325 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
|
msw
2017/01/31 17:53:16
q: did you remember to test MD and non-MD?
Peter Kasting
2017/01/31 21:31:01
The Harmony close button is a VectorIconButton ins
| |
| 326 close_position += gfx::Vector2d(-close_->width() - kClosePaddingRightMd, | 326 close_position += gfx::Vector2d(-close_->width() - kClosePaddingRightMd, |
| 327 kClosePaddingTopMd); | 327 kClosePaddingTopMd); |
| 328 } else { | 328 } else { |
| 329 close_position += | 329 close_position += |
| 330 gfx::Vector2d(-close_->width() - kClosePaddingRight, kClosePaddingTop); | 330 gfx::Vector2d(-close_->width() - kClosePaddingRight, kClosePaddingTop); |
| 331 } | 331 } |
| 332 close_->SetPosition(close_position); | 332 close_->SetPosition(close_position); |
| 333 | 333 |
| 334 gfx::Size title_icon_pref_size(title_icon_->GetPreferredSize()); | 334 gfx::Size title_icon_pref_size(title_icon_->GetPreferredSize()); |
| 335 int padding = 0; | 335 int padding = 0; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 346 title_->SetPosition(gfx::Point( | 346 title_->SetPosition(gfx::Point( |
| 347 title_label_x, bounds.y() + (title_height - title_->height()) / 2)); | 347 title_label_x, bounds.y() + (title_height - title_->height()) / 2)); |
| 348 } | 348 } |
| 349 | 349 |
| 350 title_icon_->SetBounds(bounds.x(), bounds.y(), title_icon_pref_size.width(), | 350 title_icon_->SetBounds(bounds.x(), bounds.y(), title_icon_pref_size.width(), |
| 351 title_height); | 351 title_height); |
| 352 bounds.set_width(title_->bounds().right() - bounds.x()); | 352 bounds.set_width(title_->bounds().right() - bounds.x()); |
| 353 bounds.set_height(title_height); | 353 bounds.set_height(title_height); |
| 354 | 354 |
| 355 if (footnote_container_) { | 355 if (footnote_container_) { |
| 356 gfx::Rect local_bounds = GetContentsBounds(); | 356 const int width = contents_bounds.width(); |
| 357 int height = footnote_container_->GetHeightForWidth(local_bounds.width()); | 357 const int height = footnote_container_->GetHeightForWidth(width); |
| 358 footnote_container_->SetBounds(local_bounds.x(), | 358 footnote_container_->SetBounds( |
| 359 local_bounds.bottom() - height, | 359 contents_bounds.x(), contents_bounds.bottom() - height, width, height); |
| 360 local_bounds.width(), height); | |
| 361 } | 360 } |
| 362 } | 361 } |
| 363 | 362 |
| 364 void BubbleFrameView::OnThemeChanged() { | 363 void BubbleFrameView::OnThemeChanged() { |
| 365 UpdateWindowTitle(); | 364 UpdateWindowTitle(); |
| 366 ResetWindowControls(); | 365 ResetWindowControls(); |
| 367 UpdateWindowIcon(); | 366 UpdateWindowIcon(); |
| 368 } | 367 } |
| 369 | 368 |
| 370 void BubbleFrameView::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 369 void BubbleFrameView::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 size.Enlarge(client_insets.width(), client_insets.height()); | 541 size.Enlarge(client_insets.width(), client_insets.height()); |
| 543 size.SetToMax(gfx::Size(title_bar_width, 0)); | 542 size.SetToMax(gfx::Size(title_bar_width, 0)); |
| 544 | 543 |
| 545 if (footnote_container_) | 544 if (footnote_container_) |
| 546 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); | 545 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); |
| 547 | 546 |
| 548 return size; | 547 return size; |
| 549 } | 548 } |
| 550 | 549 |
| 551 } // namespace views | 550 } // namespace views |
| OLD | NEW |