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

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 comments 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 views::Widget* container,
39 int client_left_inset,
40 int client_right_inset);
38 virtual ~HeaderLayout() {} 41 virtual ~HeaderLayout() {}
39 42
40 // Overridden from LayoutManager 43 // Overridden from LayoutManager
41 virtual void Layout(views::View* host); 44 virtual void Layout(views::View* host);
42 virtual gfx::Size GetPreferredSize(views::View* host); 45 virtual gfx::Size GetPreferredSize(views::View* host);
43 46
44 private: 47 private:
45 views::Widget* container_; 48 views::Widget* container_;
49 int client_left_inset_;
50 int client_right_inset_;
46 51
47 DISALLOW_COPY_AND_ASSIGN(HeaderLayout); 52 DISALLOW_COPY_AND_ASSIGN(HeaderLayout);
48 }; 53 };
49 54
55 HeaderLayout::HeaderLayout(
56 views::Widget* container,
57 int client_left_inset,
58 int client_right_inset)
59 : container_(container),
60 client_left_inset_(client_left_inset),
61 client_right_inset_(client_right_inset) {}
62
50 void HeaderLayout::Layout(views::View* host) { 63 void HeaderLayout::Layout(views::View* host) {
51 if (!host->has_children()) 64 if (!host->has_children())
52 return; 65 return;
53 66
54 int horizontal_padding = ConstrainedWindow::kHorizontalPadding; 67 int top_padding = ConstrainedWindow::kCloseButtonPadding;
55 int vertical_padding = ConstrainedWindow::kVerticalPadding; 68 int left_padding = ConstrainedWindow::kHorizontalPadding;
56 int row_padding = ConstrainedWindow::kRowPadding; 69 int right_padding = ConstrainedWindow::kCloseButtonPadding;
57 70
58 views::View* header = host->child_at(0); 71 views::View* header = host->child_at(0);
59 gfx::Size preferred_size = GetPreferredSize(host); 72 gfx::Size preferred_size = GetPreferredSize(host);
60 int width = preferred_size.width() - 2 * horizontal_padding; 73 int width = preferred_size.width() - left_padding - right_padding;
61 int height = preferred_size.height() - vertical_padding - row_padding; 74 int height = preferred_size.height() - top_padding;
62 75
63 header->SetBounds(horizontal_padding, vertical_padding, width, height); 76 header->SetBounds(left_padding, top_padding, width, height);
64 } 77 }
65 78
66 gfx::Size HeaderLayout::GetPreferredSize(views::View* host) { 79 gfx::Size HeaderLayout::GetPreferredSize(views::View* host) {
67 int horizontal_padding = ConstrainedWindow::kHorizontalPadding; 80 int left_padding = ConstrainedWindow::kHorizontalPadding;
68 int vertical_padding = ConstrainedWindow::kVerticalPadding; 81 int top_padding = ConstrainedWindow::kCloseButtonPadding;
69 int row_padding = ConstrainedWindow::kRowPadding; 82 int right_padding = ConstrainedWindow::kCloseButtonPadding;
70 83
71 views::View* header = host->child_at(0); 84 views::View* header = host->child_at(0);
72 views::View* client_view = container_->client_view(); 85 views::View* client_view = container_->client_view();
73 86
74 gfx::Size header_size = header ? header->GetPreferredSize() : gfx::Size(); 87 gfx::Size header_size = header ? header->GetPreferredSize() : gfx::Size();
75 gfx::Size client_size = 88 gfx::Size client_size =
76 client_view ? client_view->GetPreferredSize() : gfx::Size(); 89 client_view ? client_view->GetPreferredSize() : gfx::Size();
77 int width = std::max(client_size.width(), header_size.width()) + 90 int width = std::max(
78 2 * horizontal_padding; 91 client_left_inset_ + client_size.width() + client_right_inset_,
79 int height = vertical_padding + header_size.height() + row_padding; 92 left_padding + header_size.width() + right_padding);
93 int height = header_size.height() + top_padding;
80 return gfx::Size(width, height); 94 return gfx::Size(width, height);
81 } 95 }
82 96
83 } // namespace 97 } // namespace
84 98
85 ConstrainedWindowFrameSimple::HeaderViews::HeaderViews( 99 ConstrainedWindowFrameSimple::HeaderViews::HeaderViews(
86 views::View* header, 100 views::View* header,
87 views::Label* title_label, 101 views::Label* title_label,
88 views::Button* close_button) 102 views::Button* close_button)
89 : header(header), 103 : header(header),
90 title_label(title_label), 104 title_label(title_label),
91 close_button(close_button) { 105 close_button(close_button) {
92 DCHECK(header); 106 DCHECK(header);
93 } 107 }
94 108
95 ConstrainedWindowFrameSimple::ConstrainedWindowFrameSimple( 109 ConstrainedWindowFrameSimple::ConstrainedWindowFrameSimple(
96 ConstrainedWindowViews* container) 110 ConstrainedWindowViews* container)
97 : container_(container) { 111 : container_(container),
112 client_insets_(ConstrainedWindow::kClientTopPadding,
Peter Kasting 2012/10/10 20:22:26 I didn't totally grasp why you wanted this member.
please use gerrit instead 2012/10/11 00:34:57 I have not decided how this is going to be done. F
113 ConstrainedWindow::kHorizontalPadding,
114 ConstrainedWindow::kClientBottomPadding,
115 ConstrainedWindow::kHorizontalPadding) {
98 container_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); 116 container_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM);
99 117
100 layout_ = new HeaderLayout(container_); 118 layout_ = new HeaderLayout(container_, client_insets_.left(),
119 client_insets_.right());
Peter Kasting 2012/10/10 20:22:26 It seems like the header shouldn't have to worry a
please use gerrit instead 2012/10/11 00:34:57 Done.
101 SetLayoutManager(layout_); 120 SetLayoutManager(layout_);
102 121
103 SetHeaderView(CreateDefaultHeaderView()); 122 SetHeaderView(CreateDefaultHeaderView());
104 123
105 set_background(views::Background::CreateSolidBackground( 124 set_background(views::Background::CreateSolidBackground(
106 ConstrainedWindow::GetBackgroundColor())); 125 ConstrainedWindow::GetBackgroundColor()));
126
127 set_border(views::Border::CreateEmptyBorder(client_insets_.top(),
128 client_insets_.left(),
129 client_insets_.bottom(),
130 client_insets_.right()));
107 } 131 }
108 132
109 ConstrainedWindowFrameSimple::~ConstrainedWindowFrameSimple() { 133 ConstrainedWindowFrameSimple::~ConstrainedWindowFrameSimple() {
110 } 134 }
111 135
112 void ConstrainedWindowFrameSimple::SetHeaderView(HeaderViews* header_views) 136 void ConstrainedWindowFrameSimple::SetHeaderView(HeaderViews* header_views)
113 { 137 {
114 RemoveAllChildViews(true); 138 RemoveAllChildViews(true);
115 139
116 header_views_.reset(header_views); 140 header_views_.reset(header_views);
117 141
118 AddChildView(header_views_->header); 142 AddChildView(header_views_->header);
119 } 143 }
120 144
121 HeaderViews* ConstrainedWindowFrameSimple::CreateDefaultHeaderView() { 145 HeaderViews* ConstrainedWindowFrameSimple::CreateDefaultHeaderView() {
146 const int kTitleTopPadding = ConstrainedWindow::kTitleTopPadding -
147 ConstrainedWindow::kCloseButtonPadding;
148 const int kTitleLeftPadding = 0;
149 const int kTitleBottomPadding = 0;
150 const int kTitleRightPadding = 0;
151
122 views::View* header_view = new views::View; 152 views::View* header_view = new views::View;
123 153
124 views::GridLayout* grid_layout = new views::GridLayout(header_view); 154 views::GridLayout* grid_layout = new views::GridLayout(header_view);
125 header_view->SetLayoutManager(grid_layout); 155 header_view->SetLayoutManager(grid_layout);
126 156
127 views::ColumnSet* header_cs = grid_layout->AddColumnSet(0); 157 views::ColumnSet* header_cs = grid_layout->AddColumnSet(0);
128 header_cs->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 0, 158 header_cs->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 0,
129 views::GridLayout::USE_PREF, 0, 0); // Title. 159 views::GridLayout::USE_PREF, 0, 0); // Title.
130 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); 160 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
131 header_cs->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 0, 161 header_cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING,
132 views::GridLayout::USE_PREF, 0, 0); // Close Button. 162 0, views::GridLayout::USE_PREF, 0, 0); // Close Button.
133 163
134 // Header row. 164 // Header row.
135 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 165 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
136 grid_layout->StartRow(0, 0); 166 grid_layout->StartRow(0, 0);
167
137 views::Label* title_label = new views::Label(); 168 views::Label* title_label = new views::Label();
138 title_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 169 title_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
139 title_label->SetFont(rb.GetFont(ConstrainedWindow::kTitleFontStyle)); 170 title_label->SetFont(rb.GetFont(ConstrainedWindow::kTitleFontStyle));
140 title_label->SetEnabledColor(ConstrainedWindow::GetTextColor()); 171 title_label->SetEnabledColor(ConstrainedWindow::GetTextColor());
141 title_label->SetText(container_->widget_delegate()->GetWindowTitle()); 172 title_label->SetText(container_->widget_delegate()->GetWindowTitle());
173 title_label->set_border(views::Border::CreateEmptyBorder(kTitleTopPadding,
174 kTitleLeftPadding, kTitleBottomPadding, kTitleRightPadding));
142 grid_layout->AddView(title_label); 175 grid_layout->AddView(title_label);
143 176
144 views::Button* close_button = CreateCloseButton(); 177 views::Button* close_button = CreateCloseButton();
145 grid_layout->AddView(close_button); 178 grid_layout->AddView(close_button);
146 179
147 return new HeaderViews(header_view, title_label, close_button); 180 return new HeaderViews(header_view, title_label, close_button);
148 } 181 }
149 182
150 gfx::Rect ConstrainedWindowFrameSimple::GetBoundsForClientView() const { 183 gfx::Rect ConstrainedWindowFrameSimple::GetBoundsForClientView() const {
151 int horizontal_padding = ConstrainedWindow::kHorizontalPadding; 184 gfx::Rect bounds(GetContentsBounds());
152 int vertical_padding = ConstrainedWindow::kVerticalPadding; 185 if (header_views_->header)
153 int row_padding = ConstrainedWindow::kRowPadding; 186 bounds.Inset(0, header_views_->header->GetPreferredSize().height(), 0, 0);
154 gfx::Size header_size = 187 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 } 188 }
164 189
165 gfx::Rect ConstrainedWindowFrameSimple::GetWindowBoundsForClientBounds( 190 gfx::Rect ConstrainedWindowFrameSimple::GetWindowBoundsForClientBounds(
166 const gfx::Rect& client_bounds) const { 191 const gfx::Rect& client_bounds) const {
167 int horizontal_padding = ConstrainedWindow::kHorizontalPadding; 192 gfx::Rect bounds(client_bounds);
168 int vertical_padding = ConstrainedWindow::kVerticalPadding; 193 bounds.Inset(-GetInsets());
169 int row_padding = ConstrainedWindow::kRowPadding; 194 if (header_views_->header)
170 gfx::Size header_size = 195 bounds.Inset(0, -header_views_->header->GetPreferredSize().height(), 0, 0);
171 header_views_->header ? 196 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 } 197 }
183 198
184 int ConstrainedWindowFrameSimple::NonClientHitTest(const gfx::Point& point) { 199 int ConstrainedWindowFrameSimple::NonClientHitTest(const gfx::Point& point) {
185 if (!bounds().Contains(point)) 200 if (!bounds().Contains(point))
186 return HTNOWHERE; 201 return HTNOWHERE;
187 return HTCLIENT; 202 return HTCLIENT;
188 } 203 }
189 204
190 void ConstrainedWindowFrameSimple::GetWindowMask(const gfx::Size& size, 205 void ConstrainedWindowFrameSimple::GetWindowMask(const gfx::Size& size,
191 gfx::Path* window_mask) { 206 gfx::Path* window_mask) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 246 }
232 247
233 views::ImageButton* ConstrainedWindowFrameSimple::CreateCloseButton() { 248 views::ImageButton* ConstrainedWindowFrameSimple::CreateCloseButton() {
234 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 249 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
235 views::ImageButton* close_button = new views::ImageButton(this); 250 views::ImageButton* close_button = new views::ImageButton(this);
236 close_button->SetImage(views::CustomButton::BS_NORMAL, 251 close_button->SetImage(views::CustomButton::BS_NORMAL,
237 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X)); 252 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X));
238 close_button->SetImage(views::CustomButton::BS_HOT, 253 close_button->SetImage(views::CustomButton::BS_HOT,
239 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER)); 254 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER));
240 close_button->SetImage(views::CustomButton::BS_PUSHED, 255 close_button->SetImage(views::CustomButton::BS_PUSHED,
241 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER)); 256 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_PRESSED));
242 return close_button; 257 return close_button;
243 } 258 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/constrained_window_frame_simple.h ('k') | chrome/browser/ui/views/tab_modal_confirm_dialog_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698