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

Side by Side Diff: chrome/browser/ui/views/constrained_window_frame_simple.cc

Issue 11077006: Correct padding and focus ring for frameless constrained window dialog (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address sail@ comment for mac usage of constants Created 8 years, 2 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
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 "chrome/browser/ui/views/constrained_window_frame_simple.h" 5 #include "chrome/browser/ui/views/constrained_window_frame_simple.h"
6 6
7 #include "chrome/browser/ui/constrained_window.h" 7 #include "chrome/browser/ui/constrained_window.h"
8 #include "chrome/browser/ui/views/constrained_window_views.h" 8 #include "chrome/browser/ui/views/constrained_window_views.h"
9 #include "grit/ui_resources.h" 9 #include "grit/ui_resources.h"
10 #include "grit/chromium_strings.h" 10 #include "grit/chromium_strings.h"
(...skipping 16 matching lines...) Expand all
27 #include "ui/views/widget/widget_delegate.h" 27 #include "ui/views/widget/widget_delegate.h"
28 28
29 namespace { 29 namespace {
30 30
31 typedef ConstrainedWindowFrameSimple::HeaderViews HeaderViews; 31 typedef ConstrainedWindowFrameSimple::HeaderViews HeaderViews;
32 32
33 // A layout manager that lays out the header view with proper padding, 33 // A layout manager that lays out the header view with proper padding,
34 // and sized to the widget's client view. 34 // and sized to the widget's client view.
35 class HeaderLayout : public views::LayoutManager { 35 class HeaderLayout : public views::LayoutManager {
36 public: 36 public:
37 explicit HeaderLayout(views::Widget* container) : container_(container) {} 37 explicit HeaderLayout() {}
38 virtual ~HeaderLayout() {} 38 virtual ~HeaderLayout() {}
39 39
40 // Overridden from LayoutManager 40 // Overridden from LayoutManager
41 virtual void Layout(views::View* host); 41 virtual void Layout(views::View* host);
42 virtual gfx::Size GetPreferredSize(views::View* host); 42 virtual gfx::Size GetPreferredSize(views::View* host);
43 43
44 private:
45 views::Widget* container_;
46
47 DISALLOW_COPY_AND_ASSIGN(HeaderLayout); 44 DISALLOW_COPY_AND_ASSIGN(HeaderLayout);
48 }; 45 };
49 46
50 void HeaderLayout::Layout(views::View* host) { 47 void HeaderLayout::Layout(views::View* host) {
51 if (!host->has_children()) 48 if (!host->has_children())
52 return; 49 return;
53 50
54 int horizontal_padding = ConstrainedWindow::kHorizontalPadding; 51 int top_padding = ConstrainedWindow::kCloseButtonPadding;
55 int vertical_padding = ConstrainedWindow::kVerticalPadding; 52 int left_padding = ConstrainedWindow::kHorizontalPadding;
56 int row_padding = ConstrainedWindow::kRowPadding; 53 int right_padding = ConstrainedWindow::kCloseButtonPadding;
57 54
58 views::View* header = host->child_at(0); 55 views::View* header = host->child_at(0);
59 gfx::Size preferred_size = GetPreferredSize(host); 56 gfx::Size preferred_size = GetPreferredSize(host);
60 int width = preferred_size.width() - 2 * horizontal_padding; 57 int width = preferred_size.width() - left_padding - right_padding;
61 int height = preferred_size.height() - vertical_padding - row_padding; 58 int height = preferred_size.height() - top_padding;
62 59
63 header->SetBounds(horizontal_padding, vertical_padding, width, height); 60 header->SetBounds(left_padding, top_padding, width, height);
64 } 61 }
65 62
66 gfx::Size HeaderLayout::GetPreferredSize(views::View* host) { 63 gfx::Size HeaderLayout::GetPreferredSize(views::View* host) {
67 int horizontal_padding = ConstrainedWindow::kHorizontalPadding; 64 int top_padding = ConstrainedWindow::kCloseButtonPadding;
68 int vertical_padding = ConstrainedWindow::kVerticalPadding; 65 int left_padding = ConstrainedWindow::kHorizontalPadding;
69 int row_padding = ConstrainedWindow::kRowPadding; 66 int right_padding = ConstrainedWindow::kCloseButtonPadding;
70 67
71 views::View* header = host->child_at(0); 68 views::View* header = host->child_at(0);
72 views::View* client_view = container_->client_view(); 69 gfx::Size header_size = header ? header->GetPreferredSize() : gfx::Size();
70 int width = std::max(host->GetPreferredSize().width(),
71 left_padding + header_size.width() + right_padding);
72 int height = header_size.height() + top_padding;
73 73
74 gfx::Size header_size = header ? header->GetPreferredSize() : gfx::Size();
75 gfx::Size client_size =
76 client_view ? client_view->GetPreferredSize() : gfx::Size();
77 int width = std::max(client_size.width(), header_size.width()) +
78 2 * horizontal_padding;
79 int height = vertical_padding + header_size.height() + row_padding;
80 return gfx::Size(width, height); 74 return gfx::Size(width, height);
81 } 75 }
82 76
83 } // namespace 77 } // namespace
84 78
85 ConstrainedWindowFrameSimple::HeaderViews::HeaderViews( 79 ConstrainedWindowFrameSimple::HeaderViews::HeaderViews(
86 views::View* header, 80 views::View* header,
87 views::Label* title_label, 81 views::Label* title_label,
88 views::Button* close_button) 82 views::Button* close_button)
89 : header(header), 83 : header(header),
90 title_label(title_label), 84 title_label(title_label),
91 close_button(close_button) { 85 close_button(close_button) {
92 DCHECK(header); 86 DCHECK(header);
93 } 87 }
94 88
95 ConstrainedWindowFrameSimple::ConstrainedWindowFrameSimple( 89 ConstrainedWindowFrameSimple::ConstrainedWindowFrameSimple(
96 ConstrainedWindowViews* container) 90 ConstrainedWindowViews* container)
97 : container_(container) { 91 : container_(container) {
98 container_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); 92 container_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM);
99 93
100 layout_ = new HeaderLayout(container_); 94 layout_ = new HeaderLayout();
101 SetLayoutManager(layout_); 95 SetLayoutManager(layout_);
102 96
103 SetHeaderView(CreateDefaultHeaderView()); 97 SetHeaderView(CreateDefaultHeaderView());
104 98
105 set_background(views::Background::CreateSolidBackground( 99 set_background(views::Background::CreateSolidBackground(
106 ConstrainedWindow::GetBackgroundColor())); 100 ConstrainedWindow::GetBackgroundColor()));
101
102 set_border(views::Border::CreateEmptyBorder(
103 ConstrainedWindow::kClientTopPadding,
104 ConstrainedWindow::kHorizontalPadding,
105 ConstrainedWindow::kClientBottomPadding,
106 ConstrainedWindow::kHorizontalPadding));
107 } 107 }
108 108
109 ConstrainedWindowFrameSimple::~ConstrainedWindowFrameSimple() { 109 ConstrainedWindowFrameSimple::~ConstrainedWindowFrameSimple() {
110 } 110 }
111 111
112 void ConstrainedWindowFrameSimple::SetHeaderView(HeaderViews* header_views) 112 void ConstrainedWindowFrameSimple::SetHeaderView(HeaderViews* header_views)
113 { 113 {
114 RemoveAllChildViews(true); 114 RemoveAllChildViews(true);
115 115
116 header_views_.reset(header_views); 116 header_views_.reset(header_views);
117 117
118 AddChildView(header_views_->header); 118 AddChildView(header_views_->header);
119 } 119 }
120 120
121 HeaderViews* ConstrainedWindowFrameSimple::CreateDefaultHeaderView() { 121 HeaderViews* ConstrainedWindowFrameSimple::CreateDefaultHeaderView() {
122 const int kTitleTopPadding = ConstrainedWindow::kTitleTopPadding -
123 ConstrainedWindow::kCloseButtonPadding;
124 const int kTitleLeftPadding = 0;
125 const int kTitleBottomPadding = 0;
126 const int kTitleRightPadding = 0;
127
122 views::View* header_view = new views::View; 128 views::View* header_view = new views::View;
123 129
124 views::GridLayout* grid_layout = new views::GridLayout(header_view); 130 views::GridLayout* grid_layout = new views::GridLayout(header_view);
125 header_view->SetLayoutManager(grid_layout); 131 header_view->SetLayoutManager(grid_layout);
126 132
127 views::ColumnSet* header_cs = grid_layout->AddColumnSet(0); 133 views::ColumnSet* header_cs = grid_layout->AddColumnSet(0);
128 header_cs->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 0, 134 header_cs->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 0,
129 views::GridLayout::USE_PREF, 0, 0); // Title. 135 views::GridLayout::USE_PREF, 0, 0); // Title.
130 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); 136 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
131 header_cs->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 0, 137 header_cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING,
132 views::GridLayout::USE_PREF, 0, 0); // Close Button. 138 0, views::GridLayout::USE_PREF, 0, 0); // Close Button.
133 139
134 // Header row. 140 // Header row.
135 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 141 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
136 grid_layout->StartRow(0, 0); 142 grid_layout->StartRow(0, 0);
143
137 views::Label* title_label = new views::Label(); 144 views::Label* title_label = new views::Label();
138 title_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 145 title_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
139 title_label->SetFont(rb.GetFont(ConstrainedWindow::kTitleFontStyle)); 146 title_label->SetFont(rb.GetFont(ConstrainedWindow::kTitleFontStyle));
140 title_label->SetEnabledColor(ConstrainedWindow::GetTextColor()); 147 title_label->SetEnabledColor(ConstrainedWindow::GetTextColor());
141 title_label->SetText(container_->widget_delegate()->GetWindowTitle()); 148 title_label->SetText(container_->widget_delegate()->GetWindowTitle());
149 title_label->set_border(views::Border::CreateEmptyBorder(kTitleTopPadding,
150 kTitleLeftPadding, kTitleBottomPadding, kTitleRightPadding));
142 grid_layout->AddView(title_label); 151 grid_layout->AddView(title_label);
143 152
144 views::Button* close_button = CreateCloseButton(); 153 views::Button* close_button = CreateCloseButton();
145 grid_layout->AddView(close_button); 154 grid_layout->AddView(close_button);
146 155
147 return new HeaderViews(header_view, title_label, close_button); 156 return new HeaderViews(header_view, title_label, close_button);
148 } 157 }
149 158
150 gfx::Rect ConstrainedWindowFrameSimple::GetBoundsForClientView() const { 159 gfx::Rect ConstrainedWindowFrameSimple::GetBoundsForClientView() const {
151 int horizontal_padding = ConstrainedWindow::kHorizontalPadding; 160 gfx::Rect bounds(GetContentsBounds());
152 int vertical_padding = ConstrainedWindow::kVerticalPadding; 161 if (header_views_->header)
153 int row_padding = ConstrainedWindow::kRowPadding; 162 bounds.Inset(0, header_views_->header->GetPreferredSize().height(), 0, 0);
154 gfx::Size header_size = 163 return bounds;
155 header_views_->header ?
156 header_views_->header->GetPreferredSize() : gfx::Size();
157
158 return gfx::Rect(horizontal_padding,
159 vertical_padding + header_size.height() + row_padding,
160 std::max(0, width() - 2 * horizontal_padding),
161 std::max(0, (height() - 2 * vertical_padding -
162 header_size.height() - row_padding)));
163 } 164 }
164 165
165 gfx::Rect ConstrainedWindowFrameSimple::GetWindowBoundsForClientBounds( 166 gfx::Rect ConstrainedWindowFrameSimple::GetWindowBoundsForClientBounds(
166 const gfx::Rect& client_bounds) const { 167 const gfx::Rect& client_bounds) const {
167 int horizontal_padding = ConstrainedWindow::kHorizontalPadding; 168 gfx::Rect bounds(client_bounds);
168 int vertical_padding = ConstrainedWindow::kVerticalPadding; 169 bounds.Inset(-GetInsets());
169 int row_padding = ConstrainedWindow::kRowPadding; 170 if (header_views_->header)
170 gfx::Size header_size = 171 bounds.Inset(0, -header_views_->header->GetPreferredSize().height(), 0, 0);
171 header_views_->header ? 172 return bounds;
172 header_views_->header->GetPreferredSize() : gfx::Size();
173
174 int x = client_bounds.x() - horizontal_padding;
175 int y = client_bounds.y() - vertical_padding - header_size.height() -
176 row_padding;
177 int width = client_bounds.width() + 2 * horizontal_padding;
178 int height = client_bounds.height() + 2 * vertical_padding +
179 header_size.height() + row_padding;
180
181 return gfx::Rect(x, y, width, height);
182 } 173 }
183 174
184 int ConstrainedWindowFrameSimple::NonClientHitTest(const gfx::Point& point) { 175 int ConstrainedWindowFrameSimple::NonClientHitTest(const gfx::Point& point) {
185 if (!bounds().Contains(point)) 176 if (!bounds().Contains(point))
186 return HTNOWHERE; 177 return HTNOWHERE;
187 return HTCLIENT; 178 return HTCLIENT;
188 } 179 }
189 180
190 void ConstrainedWindowFrameSimple::GetWindowMask(const gfx::Size& size, 181 void ConstrainedWindowFrameSimple::GetWindowMask(const gfx::Size& size,
191 gfx::Path* window_mask) { 182 gfx::Path* window_mask) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 222 }
232 223
233 views::ImageButton* ConstrainedWindowFrameSimple::CreateCloseButton() { 224 views::ImageButton* ConstrainedWindowFrameSimple::CreateCloseButton() {
234 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 225 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
235 views::ImageButton* close_button = new views::ImageButton(this); 226 views::ImageButton* close_button = new views::ImageButton(this);
236 close_button->SetImage(views::CustomButton::BS_NORMAL, 227 close_button->SetImage(views::CustomButton::BS_NORMAL,
237 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X)); 228 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X));
238 close_button->SetImage(views::CustomButton::BS_HOT, 229 close_button->SetImage(views::CustomButton::BS_HOT,
239 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER)); 230 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER));
240 close_button->SetImage(views::CustomButton::BS_PUSHED, 231 close_button->SetImage(views::CustomButton::BS_PUSHED,
241 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER)); 232 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_PRESSED));
242 return close_button; 233 return close_button;
243 } 234 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698