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

Side by Side Diff: ui/views/bubble/bubble_frame_view.cc

Issue 339063002: Fix the BubbleFrameView close button insets. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 (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 8
9 #include "grit/ui_resources.h" 9 #include "grit/ui_resources.h"
10 #include "ui/base/hit_test.h" 10 #include "ui/base/hit_test.h"
11 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/gfx/path.h" 12 #include "ui/gfx/path.h"
13 #include "ui/gfx/screen.h" 13 #include "ui/gfx/screen.h"
14 #include "ui/gfx/skia_util.h" 14 #include "ui/gfx/skia_util.h"
15 #include "ui/native_theme/native_theme.h" 15 #include "ui/native_theme/native_theme.h"
16 #include "ui/views/bubble/bubble_border.h" 16 #include "ui/views/bubble/bubble_border.h"
17 #include "ui/views/controls/button/label_button.h" 17 #include "ui/views/controls/button/label_button.h"
18 #include "ui/views/widget/widget.h" 18 #include "ui/views/widget/widget.h"
19 #include "ui/views/widget/widget_delegate.h" 19 #include "ui/views/widget/widget_delegate.h"
20 #include "ui/views/window/client_view.h" 20 #include "ui/views/window/client_view.h"
21 21
22 namespace { 22 namespace {
23 23
24 // Padding, in pixels, for the title view, when it exists. 24 // Insets for the title bar views in pixels.
25 const int kTitleTopInset = 12; 25 const int kTitleTopInset = 12;
26 const int kTitleLeftInset = 19; 26 const int kTitleLeftInset = 19;
27 const int kTitleBottomInset = 12; 27 const int kTitleBottomInset = 12;
28 const int kTitleRightInset = 7;
28 29
29 // Get the |vertical| or horizontal amount that |available_bounds| overflows 30 // Get the |vertical| or horizontal amount that |available_bounds| overflows
30 // |window_bounds|. 31 // |window_bounds|.
31 int GetOffScreenLength(const gfx::Rect& available_bounds, 32 int GetOffScreenLength(const gfx::Rect& available_bounds,
32 const gfx::Rect& window_bounds, 33 const gfx::Rect& window_bounds,
33 bool vertical) { 34 bool vertical) {
34 if (available_bounds.IsEmpty() || available_bounds.Contains(window_bounds)) 35 if (available_bounds.IsEmpty() || available_bounds.Contains(window_bounds))
35 return 0; 36 return 0;
36 37
37 // window_bounds 38 // window_bounds
(...skipping 13 matching lines...) Expand all
51 52
52 } // namespace 53 } // namespace
53 54
54 namespace views { 55 namespace views {
55 56
56 // static 57 // static
57 const char BubbleFrameView::kViewClassName[] = "BubbleFrameView"; 58 const char BubbleFrameView::kViewClassName[] = "BubbleFrameView";
58 59
59 // static 60 // static
60 gfx::Insets BubbleFrameView::GetTitleInsets() { 61 gfx::Insets BubbleFrameView::GetTitleInsets() {
61 return gfx::Insets(kTitleTopInset, kTitleLeftInset, kTitleBottomInset, 0); 62 return gfx::Insets(kTitleTopInset, kTitleLeftInset,
63 kTitleBottomInset, kTitleRightInset);
62 } 64 }
63 65
64 BubbleFrameView::BubbleFrameView(const gfx::Insets& content_margins) 66 BubbleFrameView::BubbleFrameView(const gfx::Insets& content_margins)
65 : bubble_border_(NULL), 67 : bubble_border_(NULL),
66 content_margins_(content_margins), 68 content_margins_(content_margins),
67 title_(NULL), 69 title_(NULL),
68 close_(NULL), 70 close_(NULL),
69 titlebar_extra_view_(NULL) { 71 titlebar_extra_view_(NULL) {
70 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 72 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
71 title_ = new Label(base::string16(), 73 title_ = new Label(base::string16(),
72 rb.GetFontList(ui::ResourceBundle::MediumFont)); 74 rb.GetFontList(ui::ResourceBundle::MediumFont));
73 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 75 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
74 AddChildView(title_); 76 AddChildView(title_);
75 77
76 close_ = new LabelButton(this, base::string16()); 78 close_ = new LabelButton(this, base::string16());
77 close_->SetImage(CustomButton::STATE_NORMAL, 79 close_->SetImage(CustomButton::STATE_NORMAL,
78 *rb.GetImageNamed(IDR_CLOSE_DIALOG).ToImageSkia()); 80 *rb.GetImageNamed(IDR_CLOSE_DIALOG).ToImageSkia());
79 close_->SetImage(CustomButton::STATE_HOVERED, 81 close_->SetImage(CustomButton::STATE_HOVERED,
80 *rb.GetImageNamed(IDR_CLOSE_DIALOG_H).ToImageSkia()); 82 *rb.GetImageNamed(IDR_CLOSE_DIALOG_H).ToImageSkia());
81 close_->SetImage(CustomButton::STATE_PRESSED, 83 close_->SetImage(CustomButton::STATE_PRESSED,
82 *rb.GetImageNamed(IDR_CLOSE_DIALOG_P).ToImageSkia()); 84 *rb.GetImageNamed(IDR_CLOSE_DIALOG_P).ToImageSkia());
85 close_->SetBorder(scoped_ptr<Border>());
83 close_->SetSize(close_->GetPreferredSize()); 86 close_->SetSize(close_->GetPreferredSize());
84 close_->SetBorder(scoped_ptr<Border>());
85 close_->SetVisible(false); 87 close_->SetVisible(false);
86 AddChildView(close_); 88 AddChildView(close_);
87 } 89 }
88 90
89 BubbleFrameView::~BubbleFrameView() {} 91 BubbleFrameView::~BubbleFrameView() {}
90 92
91 gfx::Rect BubbleFrameView::GetBoundsForClientView() const { 93 gfx::Rect BubbleFrameView::GetBoundsForClientView() const {
92 gfx::Rect client_bounds = GetLocalBounds(); 94 gfx::Rect client_bounds = GetLocalBounds();
93 client_bounds.Inset(GetInsets()); 95 client_bounds.Inset(GetInsets());
94 client_bounds.Inset(bubble_border_->GetInsets()); 96 client_bounds.Inset(bubble_border_->GetInsets());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 gfx::Size BubbleFrameView::GetPreferredSize() const { 175 gfx::Size BubbleFrameView::GetPreferredSize() const {
174 return GetSizeForClientSize(GetWidget()->client_view()->GetPreferredSize()); 176 return GetSizeForClientSize(GetWidget()->client_view()->GetPreferredSize());
175 } 177 }
176 178
177 gfx::Size BubbleFrameView::GetMinimumSize() const { 179 gfx::Size BubbleFrameView::GetMinimumSize() const {
178 return GetSizeForClientSize(GetWidget()->client_view()->GetMinimumSize()); 180 return GetSizeForClientSize(GetWidget()->client_view()->GetMinimumSize());
179 } 181 }
180 182
181 void BubbleFrameView::Layout() { 183 void BubbleFrameView::Layout() {
182 gfx::Rect bounds(GetContentsBounds()); 184 gfx::Rect bounds(GetContentsBounds());
185 bounds.Inset(GetTitleInsets());
183 if (bounds.IsEmpty()) 186 if (bounds.IsEmpty())
184 return; 187 return;
185 188
186 // Small additional insets yield the desired 10px visual close button insets. 189 // The close button top inset is actually smaller than the title top inset.
187 bounds.Inset(0, 0, close_->width() + 1, 0); 190 close_->SetPosition(gfx::Point(bounds.right() - close_->width(),
188 close_->SetPosition(gfx::Point(bounds.right(), bounds.y() + 2)); 191 bounds.y() - 5));
189 192
190 gfx::Rect title_bounds(bounds);
191 title_bounds.Inset(kTitleLeftInset, kTitleTopInset, 0, 0);
192 gfx::Size title_size(title_->GetPreferredSize()); 193 gfx::Size title_size(title_->GetPreferredSize());
193 const int title_width = std::max(0, close_->bounds().x() - title_bounds.x()); 194 const int title_width = std::max(0, close_->x() - bounds.x());
194 title_size.SetToMin(gfx::Size(title_width, title_size.height())); 195 title_size.SetToMin(gfx::Size(title_width, title_size.height()));
195 title_bounds.set_size(title_size); 196 bounds.set_size(title_size);
196 title_->SetBoundsRect(title_bounds); 197 title_->SetBoundsRect(bounds);
197 198
198 if (titlebar_extra_view_) { 199 if (titlebar_extra_view_) {
199 const int extra_width = close_->bounds().x() - title_->bounds().right(); 200 const int extra_width = close_->x() - title_->bounds().right();
200 gfx::Size size = titlebar_extra_view_->GetPreferredSize(); 201 gfx::Size size = titlebar_extra_view_->GetPreferredSize();
201 size.SetToMin(gfx::Size(std::max(0, extra_width), size.height())); 202 size.SetToMin(gfx::Size(std::max(0, extra_width), size.height()));
202 gfx::Rect titlebar_extra_view_bounds( 203 gfx::Rect titlebar_extra_view_bounds(
203 bounds.right() - size.width(), 204 close_->x() - size.width(),
204 title_bounds.y(), 205 bounds.y(),
205 size.width(), 206 size.width(),
206 title_bounds.height()); 207 bounds.height());
207 titlebar_extra_view_bounds.Subtract(title_bounds); 208 titlebar_extra_view_bounds.Subtract(bounds);
208 titlebar_extra_view_->SetBoundsRect(titlebar_extra_view_bounds); 209 titlebar_extra_view_->SetBoundsRect(titlebar_extra_view_bounds);
209 } 210 }
210 } 211 }
211 212
212 const char* BubbleFrameView::GetClassName() const { 213 const char* BubbleFrameView::GetClassName() const {
213 return kViewClassName; 214 return kViewClassName;
214 } 215 }
215 216
216 void BubbleFrameView::ChildPreferredSizeChanged(View* child) { 217 void BubbleFrameView::ChildPreferredSizeChanged(View* child) {
217 if (child == titlebar_extra_view_ || child == title_) 218 if (child == titlebar_extra_view_ || child == title_)
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 if (titlebar_extra_view_ != NULL) 357 if (titlebar_extra_view_ != NULL)
357 title_bar_width += titlebar_extra_view_->GetPreferredSize().width(); 358 title_bar_width += titlebar_extra_view_->GetPreferredSize().width();
358 gfx::Size size(client_size); 359 gfx::Size size(client_size);
359 size.SetToMax(gfx::Size(title_bar_width, 0)); 360 size.SetToMax(gfx::Size(title_bar_width, 0));
360 const gfx::Insets insets(GetInsets()); 361 const gfx::Insets insets(GetInsets());
361 size.Enlarge(insets.width(), insets.height()); 362 size.Enlarge(insets.width(), insets.height());
362 return size; 363 return size;
363 } 364 }
364 365
365 } // namespace views 366 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698