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

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

Issue 11044020: Make Web Intents picker in Views conform to latest mocks (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Move link underline into a separate CL 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/constrained_window_constants.h" 8 #include "chrome/browser/ui/constrained_window_constants.h"
9 #include "chrome/browser/ui/views/constrained_window_views.h" 9 #include "chrome/browser/ui/views/constrained_window_views.h"
10 #include "grit/ui_resources.h" 10 #include "grit/ui_resources.h"
(...skipping 11 matching lines...) Expand all
22 #include "ui/views/controls/label.h" 22 #include "ui/views/controls/label.h"
23 #include "ui/views/controls/button/image_button.h" 23 #include "ui/views/controls/button/image_button.h"
24 #include "ui/views/layout/grid_layout.h" 24 #include "ui/views/layout/grid_layout.h"
25 #include "ui/views/layout/layout_manager.h" 25 #include "ui/views/layout/layout_manager.h"
26 #include "ui/views/layout/layout_constants.h" 26 #include "ui/views/layout/layout_constants.h"
27 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
28 #include "ui/views/widget/widget_delegate.h" 28 #include "ui/views/widget/widget_delegate.h"
29 29
30 namespace { 30 namespace {
31 31
32 typedef ConstrainedWindowFrameSimple::HeaderViews HeaderViews; 32 views::Label* CreateTitleLabel(const string16& title) {
33 33 const int kTitleTopPadding = ConstrainedWindowConstants::kTitleTopPadding -
34 // A layout manager that lays out the header view with proper padding, 34 ConstrainedWindowConstants::kCloseButtonPadding;
Peter Kasting 2012/10/15 21:46:54 Nit: Add a comment about why we subtract kCloseBut
please use gerrit instead 2012/10/16 00:12:23 Inlined the whole thing and added a comment for su
35 // and sized to the widget's client view. 35 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
36 class HeaderLayout : public views::LayoutManager { 36 views::Label* title_label = new views::Label(title);
37 public: 37 title_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
38 explicit HeaderLayout() {} 38 title_label->SetFont(rb.GetFont(ConstrainedWindowConstants::kTitleFontStyle));
39 virtual ~HeaderLayout() {} 39 title_label->SetEnabledColor(ConstrainedWindow::GetTextColor());
40 40 title_label->set_border(views::Border::CreateEmptyBorder(
41 // Overridden from LayoutManager 41 kTitleTopPadding, 0, 0, 0));
42 virtual void Layout(views::View* host); 42 return title_label;
43 virtual gfx::Size GetPreferredSize(views::View* host);
44
45 DISALLOW_COPY_AND_ASSIGN(HeaderLayout);
46 };
47
48 void HeaderLayout::Layout(views::View* host) {
49 if (!host->has_children())
50 return;
51
52 int top_padding = ConstrainedWindowConstants::kCloseButtonPadding;
53 int left_padding = ConstrainedWindowConstants::kHorizontalPadding;
54 int right_padding = ConstrainedWindowConstants::kCloseButtonPadding;
55
56 views::View* header = host->child_at(0);
57 gfx::Size preferred_size = GetPreferredSize(host);
58 int width = preferred_size.width() - left_padding - right_padding;
59 int height = preferred_size.height() - top_padding;
60
61 header->SetBounds(left_padding, top_padding, width, height);
62 } 43 }
63 44
64 gfx::Size HeaderLayout::GetPreferredSize(views::View* host) { 45 views::ImageButton* CreateCloseButton(views::ButtonListener* listener) {
65 int top_padding = ConstrainedWindowConstants::kCloseButtonPadding; 46 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
66 int left_padding = ConstrainedWindowConstants::kHorizontalPadding; 47 views::ImageButton* close_button = new views::ImageButton(listener);
67 int right_padding = ConstrainedWindowConstants::kCloseButtonPadding; 48 close_button->SetImage(views::CustomButton::BS_NORMAL,
49 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X));
50 close_button->SetImage(views::CustomButton::BS_HOT,
51 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER));
52 close_button->SetImage(views::CustomButton::BS_PUSHED,
53 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_PRESSED));
54 return close_button;
55 }
68 56
69 views::View* header = host->child_at(0); 57 views::View* CreateHeader(
70 gfx::Size header_size = header ? header->GetPreferredSize() : gfx::Size(); 58 views::View* header_child,
Peter Kasting 2012/10/15 21:46:54 Nit: Place on previous line, indent next line even
please use gerrit instead 2012/10/16 00:12:23 Not applicable after inlining that you requested.
71 int width = std::max(host->GetPreferredSize().width(), 59 views::ImageButton* close_button) {
72 left_padding + header_size.width() + right_padding); 60 const int kHeaderBottomPadding = 0;
Peter Kasting 2012/10/15 21:46:54 Nit: I'd just write 0 in the SetInsets() call
please use gerrit instead 2012/10/16 00:12:23 Done.
73 int height = header_size.height() + top_padding; 61 views::View* header = new views::View();
74 62 views::GridLayout* header_layout = new views::GridLayout(header);
75 return gfx::Size(width, height); 63 header_layout->SetInsets(ConstrainedWindowConstants::kCloseButtonPadding,
64 ConstrainedWindowConstants::kHorizontalPadding,
65 kHeaderBottomPadding,
66 ConstrainedWindowConstants::kCloseButtonPadding);
67 header->SetLayoutManager(header_layout);
68 views::ColumnSet* cs = header_layout->AddColumnSet(0);
69 cs->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1,
70 views::GridLayout::USE_PREF, 0, 0); // Title.
71 cs->AddPaddingColumn(0, ConstrainedWindowConstants::kCloseButtonPadding);
72 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING, 0,
73 views::GridLayout::USE_PREF, 0, 0); // Close Button.
74 header_layout->StartRow(0, 0);
75 header_layout->AddView(header_child);
76 header_layout->AddView(close_button);
77 header->Layout();
Peter Kasting 2012/10/15 21:46:54 Is this call necessary? Shouldn't this happen aut
please use gerrit instead 2012/10/16 00:12:23 Removed and the UI still works as expected. You're
78 return header;
76 } 79 }
77 80
78 } // namespace 81 } // namespace
79 82
80 ConstrainedWindowFrameSimple::HeaderViews::HeaderViews(
81 views::View* header,
82 views::Label* title_label,
83 views::Button* close_button)
84 : header(header),
85 title_label(title_label),
86 close_button(close_button) {
87 DCHECK(header);
88 }
89
90 ConstrainedWindowFrameSimple::ConstrainedWindowFrameSimple( 83 ConstrainedWindowFrameSimple::ConstrainedWindowFrameSimple(
91 ConstrainedWindowViews* container) 84 ConstrainedWindowViews* container)
92 : container_(container) { 85 : container_(container),
86 header_(NULL),
87 title_label_(CreateTitleLabel(
88 container->widget_delegate()->GetWindowTitle())),
89 ALLOW_THIS_IN_INITIALIZER_LIST(close_button_(CreateCloseButton(this))) {
93 container_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); 90 container_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM);
94 91
95 layout_ = new HeaderLayout(); 92 header_ = CreateHeader(title_label_, close_button_);
96 SetLayoutManager(layout_);
97 93
98 SetHeaderView(CreateDefaultHeaderView()); 94 views::GridLayout* layout = new views::GridLayout(this);
95 SetLayoutManager(layout);
96 layout->AddColumnSet(0)->AddColumn(
97 views::GridLayout::FILL, views::GridLayout::LEADING, 1,
98 views::GridLayout::USE_PREF, 0, 0);
99 layout->StartRow(0, 0);
100 layout->AddView(header_);
101 Layout();
99 102
100 set_background(views::Background::CreateSolidBackground( 103 set_background(views::Background::CreateSolidBackground(
101 ConstrainedWindow::GetBackgroundColor())); 104 ConstrainedWindow::GetBackgroundColor()));
102
103 set_border(views::Border::CreateEmptyBorder(
104 ConstrainedWindowConstants::kClientTopPadding,
105 ConstrainedWindowConstants::kHorizontalPadding,
106 ConstrainedWindowConstants::kClientBottomPadding,
107 ConstrainedWindowConstants::kHorizontalPadding));
108 } 105 }
109 106
110 ConstrainedWindowFrameSimple::~ConstrainedWindowFrameSimple() { 107 ConstrainedWindowFrameSimple::~ConstrainedWindowFrameSimple() {
111 } 108 }
112 109
113 void ConstrainedWindowFrameSimple::SetHeaderView(HeaderViews* header_views)
114 {
115 RemoveAllChildViews(true);
116
117 header_views_.reset(header_views);
118
119 AddChildView(header_views_->header);
120 }
121
122 HeaderViews* ConstrainedWindowFrameSimple::CreateDefaultHeaderView() {
123 const int kTitleTopPadding = ConstrainedWindowConstants::kTitleTopPadding -
124 ConstrainedWindowConstants::kCloseButtonPadding;
125 const int kTitleLeftPadding = 0;
126 const int kTitleBottomPadding = 0;
127 const int kTitleRightPadding = 0;
128
129 views::View* header_view = new views::View;
130
131 views::GridLayout* grid_layout = new views::GridLayout(header_view);
132 header_view->SetLayoutManager(grid_layout);
133
134 views::ColumnSet* header_cs = grid_layout->AddColumnSet(0);
135 header_cs->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 0,
136 views::GridLayout::USE_PREF, 0, 0); // Title.
137 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
138 header_cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING,
139 0, views::GridLayout::USE_PREF, 0, 0); // Close Button.
140
141 // Header row.
142 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
143 grid_layout->StartRow(0, 0);
144
145 views::Label* title_label = new views::Label();
146 title_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
147 title_label->SetFont(rb.GetFont(ConstrainedWindowConstants::kTitleFontStyle));
148 title_label->SetEnabledColor(ConstrainedWindow::GetTextColor());
149 title_label->SetText(container_->widget_delegate()->GetWindowTitle());
150 title_label->set_border(views::Border::CreateEmptyBorder(kTitleTopPadding,
151 kTitleLeftPadding, kTitleBottomPadding, kTitleRightPadding));
152 grid_layout->AddView(title_label);
153
154 views::Button* close_button = CreateCloseButton();
155 grid_layout->AddView(close_button);
156
157 return new HeaderViews(header_view, title_label, close_button);
158 }
159
160 gfx::Rect ConstrainedWindowFrameSimple::GetBoundsForClientView() const { 110 gfx::Rect ConstrainedWindowFrameSimple::GetBoundsForClientView() const {
161 gfx::Rect bounds(GetContentsBounds()); 111 gfx::Rect bounds(GetContentsBounds());
162 if (header_views_->header)
163 bounds.Inset(0, header_views_->header->GetPreferredSize().height(), 0, 0);
164 return bounds; 112 return bounds;
165 } 113 }
166 114
167 gfx::Rect ConstrainedWindowFrameSimple::GetWindowBoundsForClientBounds( 115 gfx::Rect ConstrainedWindowFrameSimple::GetWindowBoundsForClientBounds(
168 const gfx::Rect& client_bounds) const { 116 const gfx::Rect& client_bounds) const {
169 gfx::Rect bounds(client_bounds); 117 gfx::Rect bounds(client_bounds);
170 bounds.Inset(-GetInsets()); 118 bounds.Inset(-GetInsets());
171 if (header_views_->header) 119 gfx::Size header_size = header_->GetPreferredSize();
Peter Kasting 2012/10/15 21:46:54 Nit: Or just inline into next line
please use gerrit instead 2012/10/16 00:12:23 Done.
172 bounds.Inset(0, -header_views_->header->GetPreferredSize().height(), 0, 0); 120 bounds.set_width(std::max(bounds.width(), header_size.width()));
173 return bounds; 121 return bounds;
174 } 122 }
175 123
176 int ConstrainedWindowFrameSimple::NonClientHitTest(const gfx::Point& point) { 124 int ConstrainedWindowFrameSimple::NonClientHitTest(const gfx::Point& point) {
177 if (!bounds().Contains(point)) 125 if (!bounds().Contains(point))
178 return HTNOWHERE; 126 return HTNOWHERE;
179 return HTCLIENT; 127 return HTCLIENT;
180 } 128 }
181 129
182 void ConstrainedWindowFrameSimple::GetWindowMask(const gfx::Size& size, 130 void ConstrainedWindowFrameSimple::GetWindowMask(const gfx::Size& size,
(...skipping 14 matching lines...) Expand all
197 window_mask->addRoundRect(rect, radii); 145 window_mask->addRoundRect(rect, radii);
198 } 146 }
199 147
200 void ConstrainedWindowFrameSimple::ResetWindowControls() { 148 void ConstrainedWindowFrameSimple::ResetWindowControls() {
201 } 149 }
202 150
203 void ConstrainedWindowFrameSimple::UpdateWindowIcon() { 151 void ConstrainedWindowFrameSimple::UpdateWindowIcon() {
204 } 152 }
205 153
206 void ConstrainedWindowFrameSimple::UpdateWindowTitle() { 154 void ConstrainedWindowFrameSimple::UpdateWindowTitle() {
207 if (!header_views_->title_label) 155 if (!title_label_)
208 return; 156 return;
209 157
210 string16 text = container_->widget_delegate()->GetWindowTitle(); 158 string16 text = container_->widget_delegate()->GetWindowTitle();
211 header_views_->title_label->SetText(text); 159 title_label_->SetText(text);
160 }
161
162 void ConstrainedWindowFrameSimple::OnBoundsChanged(
163 const gfx::Rect& previous_bounds) {
164 gfx::Rect header_bounds(header_->bounds());
165 header_bounds.set_width(std::max(header_->width(), bounds().width()));
Peter Kasting 2012/10/15 21:46:54 Is it right to use header_->width() instead of hea
please use gerrit instead 2012/10/16 00:12:23 Great catch! I've been looking for a way to resolv
166 header_->SetBounds(header_bounds.x(), header_bounds.y(),
167 header_bounds.width(), header_bounds.height());
168 views::NonClientFrameView::OnBoundsChanged(previous_bounds);
212 } 169 }
213 170
214 gfx::Size ConstrainedWindowFrameSimple::GetPreferredSize() { 171 gfx::Size ConstrainedWindowFrameSimple::GetPreferredSize() {
215 return container_->non_client_view()->GetWindowBoundsForClientBounds( 172 return GetWindowBoundsForClientBounds(
216 gfx::Rect(container_->client_view()->GetPreferredSize())).size(); 173 gfx::Rect(container_->client_view()->GetPreferredSize())).size();
217 } 174 }
218 175
219 void ConstrainedWindowFrameSimple::ButtonPressed(views::Button* sender, 176 void ConstrainedWindowFrameSimple::ButtonPressed(
Peter Kasting 2012/10/15 21:46:54 Nit: Original wrapping here was fine
please use gerrit instead 2012/10/16 00:12:23 Returned to original wrapping as you requested.
220 const ui::Event& event) { 177 views::Button* sender,
221 if (header_views_->close_button && sender == header_views_->close_button) 178 const ui::Event& event) {
222 sender->GetWidget()->Close(); 179 if (close_button_ && sender == close_button_)
Peter Kasting 2012/10/15 21:46:54 Nit: NULL-checking |close_button_| is presumably n
please use gerrit instead 2012/10/16 00:12:23 Right. Also, |close_button_| should always be non-
180 sender->GetWidget()->Close();
Peter Kasting 2012/10/15 21:46:54 Nit: Indent 2
please use gerrit instead 2012/10/16 00:12:23 Done.
223 } 181 }
224
225 views::ImageButton* ConstrainedWindowFrameSimple::CreateCloseButton() {
226 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
227 views::ImageButton* close_button = new views::ImageButton(this);
228 close_button->SetImage(views::CustomButton::BS_NORMAL,
229 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X));
230 close_button->SetImage(views::CustomButton::BS_HOT,
231 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER));
232 close_button->SetImage(views::CustomButton::BS_PUSHED,
233 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_PRESSED));
234 return close_button;
235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698