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/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
15 #include "ui/compositor/paint_context.h" | 15 #include "ui/compositor/paint_context.h" |
16 #include "ui/compositor/paint_recorder.h" | 16 #include "ui/compositor/paint_recorder.h" |
17 #include "ui/display/display.h" | 17 #include "ui/display/display.h" |
18 #include "ui/display/screen.h" | 18 #include "ui/display/screen.h" |
19 #include "ui/gfx/geometry/vector2d.h" | 19 #include "ui/gfx/geometry/vector2d.h" |
20 #include "ui/gfx/path.h" | 20 #include "ui/gfx/path.h" |
21 #include "ui/gfx/skia_util.h" | 21 #include "ui/gfx/skia_util.h" |
22 #include "ui/native_theme/native_theme.h" | 22 #include "ui/native_theme/native_theme.h" |
23 #include "ui/resources/grit/ui_resources.h" | 23 #include "ui/resources/grit/ui_resources.h" |
24 #include "ui/strings/grit/ui_strings.h" | 24 #include "ui/strings/grit/ui_strings.h" |
25 #include "ui/views/bubble/bubble_border.h" | 25 #include "ui/views/bubble/bubble_border.h" |
26 #include "ui/views/controls/button/label_button.h" | 26 #include "ui/views/controls/button/label_button.h" |
msw
2016/07/21 19:07:17
nit: remove
| |
27 #include "ui/views/controls/image_view.h" | 27 #include "ui/views/controls/image_view.h" |
28 #include "ui/views/layout/box_layout.h" | 28 #include "ui/views/layout/box_layout.h" |
29 #include "ui/views/layout/layout_constants.h" | 29 #include "ui/views/layout/layout_constants.h" |
30 #include "ui/views/resources/grit/views_resources.h" | 30 #include "ui/views/resources/grit/views_resources.h" |
31 #include "ui/views/widget/widget.h" | 31 #include "ui/views/widget/widget.h" |
32 #include "ui/views/widget/widget_delegate.h" | 32 #include "ui/views/widget/widget_delegate.h" |
33 #include "ui/views/window/client_view.h" | 33 #include "ui/views/window/client_view.h" |
34 | 34 |
35 namespace views { | 35 namespace views { |
36 | 36 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 AddChildView(title_); | 92 AddChildView(title_); |
93 | 93 |
94 close_ = CreateCloseButton(this); | 94 close_ = CreateCloseButton(this); |
95 close_->SetVisible(false); | 95 close_->SetVisible(false); |
96 AddChildView(close_); | 96 AddChildView(close_); |
97 } | 97 } |
98 | 98 |
99 BubbleFrameView::~BubbleFrameView() {} | 99 BubbleFrameView::~BubbleFrameView() {} |
100 | 100 |
101 // static | 101 // static |
102 LabelButton* BubbleFrameView::CreateCloseButton(ButtonListener* listener) { | 102 ImageButton* BubbleFrameView::CreateCloseButton(ButtonListener* listener) { |
103 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 103 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
104 LabelButton* close = new LabelButton(listener, base::string16()); | 104 ImageButton* close = new ImageButton(listener); |
105 close->SetImage(CustomButton::STATE_NORMAL, | 105 close->SetImage(CustomButton::STATE_NORMAL, |
106 *rb.GetImageNamed(IDR_CLOSE_DIALOG).ToImageSkia()); | 106 rb.GetImageNamed(IDR_CLOSE_DIALOG).ToImageSkia()); |
107 close->SetImage(CustomButton::STATE_HOVERED, | 107 close->SetImage(CustomButton::STATE_HOVERED, |
108 *rb.GetImageNamed(IDR_CLOSE_DIALOG_H).ToImageSkia()); | 108 rb.GetImageNamed(IDR_CLOSE_DIALOG_H).ToImageSkia()); |
109 close->SetImage(CustomButton::STATE_PRESSED, | 109 close->SetImage(CustomButton::STATE_PRESSED, |
110 *rb.GetImageNamed(IDR_CLOSE_DIALOG_P).ToImageSkia()); | 110 rb.GetImageNamed(IDR_CLOSE_DIALOG_P).ToImageSkia()); |
111 close->SetBorder(nullptr); | 111 close->SetBorder(nullptr); |
112 close->SetSize(close->GetPreferredSize()); | 112 close->SetSize(close->GetPreferredSize()); |
113 #if !defined(OS_WIN) | 113 #if !defined(OS_WIN) |
114 // Windows will automatically create a tooltip for the close button based on | 114 // Windows will automatically create a tooltip for the close button based on |
115 // the HTCLOSE result from NonClientHitTest(). | 115 // the HTCLOSE result from NonClientHitTest(). |
116 close->SetTooltipText(l10n_util::GetStringUTF16(IDS_APP_CLOSE)); | 116 close->SetTooltipText(l10n_util::GetStringUTF16(IDS_APP_CLOSE)); |
117 #endif | 117 #endif |
118 return close; | 118 return close; |
119 } | 119 } |
120 | 120 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 | 238 |
239 gfx::Insets BubbleFrameView::GetInsets() const { | 239 gfx::Insets BubbleFrameView::GetInsets() const { |
240 gfx::Insets insets = content_margins_; | 240 gfx::Insets insets = content_margins_; |
241 | 241 |
242 const int icon_height = title_icon_->GetPreferredSize().height(); | 242 const int icon_height = title_icon_->GetPreferredSize().height(); |
243 const int label_height = title_->GetPreferredSize().height(); | 243 const int label_height = title_->GetPreferredSize().height(); |
244 const bool has_title = icon_height > 0 || label_height > 0; | 244 const bool has_title = icon_height > 0 || label_height > 0; |
245 const int title_padding = has_title ? title_margins_.height() : 0; | 245 const int title_padding = has_title ? title_margins_.height() : 0; |
246 const int title_height = std::max(icon_height, label_height) + title_padding; | 246 const int title_height = std::max(icon_height, label_height) + title_padding; |
247 const int close_height = close_->visible() ? close_->height() : 0; | 247 const int close_height = close_->visible() ? close_->height() : 0; |
248 insets += gfx::Insets(std::max(title_height, close_height), 0, 0, 0); | 248 const int min_height = !has_title ? close_->height() : 0; |
249 insets += | |
250 gfx::Insets(std::max({title_height, close_height, min_height}), 0, 0, 0); | |
249 return insets; | 251 return insets; |
250 } | 252 } |
251 | 253 |
252 gfx::Size BubbleFrameView::GetPreferredSize() const { | 254 gfx::Size BubbleFrameView::GetPreferredSize() const { |
253 // Get the preferred size of the client area. | 255 // Get the preferred size of the client area. |
254 gfx::Size client_size = GetWidget()->client_view()->GetPreferredSize(); | 256 gfx::Size client_size = GetWidget()->client_view()->GetPreferredSize(); |
255 // Expand it to include the bubble border and space for the arrow. | 257 // Expand it to include the bubble border and space for the arrow. |
256 return GetWindowBoundsForClientBounds(gfx::Rect(client_size)).size(); | 258 return GetWindowBoundsForClientBounds(gfx::Rect(client_size)).size(); |
257 } | 259 } |
258 | 260 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
512 size.Enlarge(client_insets.width(), client_insets.height()); | 514 size.Enlarge(client_insets.width(), client_insets.height()); |
513 size.SetToMax(gfx::Size(title_bar_width, 0)); | 515 size.SetToMax(gfx::Size(title_bar_width, 0)); |
514 | 516 |
515 if (footnote_container_) | 517 if (footnote_container_) |
516 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); | 518 size.Enlarge(0, footnote_container_->GetHeightForWidth(size.width())); |
517 | 519 |
518 return size; | 520 return size; |
519 } | 521 } |
520 | 522 |
521 } // namespace views | 523 } // namespace views |
OLD | NEW |