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

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

Issue 11192014: Revert 162252 - Make Web Intents picker in Views conform to latest mocks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 | Annotate | Revision Log
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_constants.h" 8 #include "chrome/browser/ui/constrained_window_constants.h"
8 #include "chrome/browser/ui/constrained_window.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/chromium_strings.h" 11 #include "grit/chromium_strings.h"
11 #include "grit/generated_resources.h" 12 #include "grit/generated_resources.h"
12 #include "grit/google_chrome_strings.h" 13 #include "grit/google_chrome_strings.h"
13 #include "grit/shared_resources.h" 14 #include "grit/shared_resources.h"
14 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
15 #include "grit/ui_resources.h"
16 #include "ui/base/hit_test.h" 16 #include "ui/base/hit_test.h"
17 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gfx/canvas.h" 18 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/rect.h"
19 #include "ui/gfx/path.h" 20 #include "ui/gfx/path.h"
20 #include "ui/gfx/rect.h"
21 #include "ui/views/background.h" 21 #include "ui/views/background.h"
22 #include "ui/views/controls/label.h"
22 #include "ui/views/controls/button/image_button.h" 23 #include "ui/views/controls/button/image_button.h"
23 #include "ui/views/controls/label.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_constants.h" 26 #include "ui/views/layout/layout_constants.h"
26 #include "ui/views/layout/layout_manager.h" 27 #include "ui/views/widget/widget.h"
27 #include "ui/views/widget/widget_delegate.h" 28 #include "ui/views/widget/widget_delegate.h"
28 #include "ui/views/widget/widget.h" 29
30 namespace {
31
32 typedef ConstrainedWindowFrameSimple::HeaderViews HeaderViews;
33
34 // A layout manager that lays out the header view with proper padding,
35 // and sized to the widget's client view.
36 class HeaderLayout : public views::LayoutManager {
37 public:
38 explicit HeaderLayout() {}
39 virtual ~HeaderLayout() {}
40
41 // Overridden from LayoutManager
42 virtual void Layout(views::View* host);
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 }
63
64 gfx::Size HeaderLayout::GetPreferredSize(views::View* host) {
65 int top_padding = ConstrainedWindowConstants::kCloseButtonPadding;
66 int left_padding = ConstrainedWindowConstants::kHorizontalPadding;
67 int right_padding = ConstrainedWindowConstants::kCloseButtonPadding;
68
69 views::View* header = host->child_at(0);
70 gfx::Size header_size = header ? header->GetPreferredSize() : gfx::Size();
71 int width = std::max(host->GetPreferredSize().width(),
72 left_padding + header_size.width() + right_padding);
73 int height = header_size.height() + top_padding;
74
75 return gfx::Size(width, height);
76 }
77
78 } // namespace
79
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 }
29 89
30 ConstrainedWindowFrameSimple::ConstrainedWindowFrameSimple( 90 ConstrainedWindowFrameSimple::ConstrainedWindowFrameSimple(
31 ConstrainedWindowViews* container, 91 ConstrainedWindowViews* container)
32 ConstrainedWindowViews::ChromeStyleClientInsets client_insets) 92 : container_(container) {
33 : container_(container),
34 title_label_(
35 new views::Label(container->widget_delegate()->GetWindowTitle())),
36 ALLOW_THIS_IN_INITIALIZER_LIST(close_button_(
37 new views::ImageButton(this))) {
38 container_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM); 93 container_->set_frame_type(views::Widget::FRAME_TYPE_FORCE_CUSTOM);
39 94
40 views::GridLayout* layout = new views::GridLayout(this); 95 layout_ = new HeaderLayout();
41 const int kHeaderTopPadding = std::min( 96 SetLayoutManager(layout_);
42 ConstrainedWindowConstants::kCloseButtonPadding,
43 ConstrainedWindowConstants::kTitleTopPadding);
44 layout->SetInsets(kHeaderTopPadding,
45 ConstrainedWindowConstants::kHorizontalPadding,
46 0,
47 ConstrainedWindowConstants::kCloseButtonPadding);
48 SetLayoutManager(layout);
49 views::ColumnSet* cs = layout->AddColumnSet(0);
50 cs->AddColumn(views::GridLayout::FILL, views::GridLayout::LEADING, 1,
51 views::GridLayout::USE_PREF, 0, 0); // Title.
52 cs->AddPaddingColumn(0, ConstrainedWindowConstants::kCloseButtonPadding);
53 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING, 0,
54 views::GridLayout::USE_PREF, 0, 0); // Close Button.
55 97
56 layout->StartRow(0, 0); 98 SetHeaderView(CreateDefaultHeaderView());
57
58 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
59 title_label_->SetFont(rb.GetFont(
60 ConstrainedWindowConstants::kTitleFontStyle));
61 title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
62 title_label_->SetEnabledColor(ConstrainedWindow::GetTextColor());
63 title_label_->set_border(views::Border::CreateEmptyBorder(
64 ConstrainedWindowConstants::kTitleTopPadding - kHeaderTopPadding,
65 0, 0, 0));
66 layout->AddView(title_label_);
67
68 close_button_->SetImage(views::CustomButton::BS_NORMAL,
69 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X));
70 close_button_->SetImage(views::CustomButton::BS_HOT,
71 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER));
72 close_button_->SetImage(views::CustomButton::BS_PUSHED,
73 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_PRESSED));
74 close_button_->set_border(views::Border::CreateEmptyBorder(
75 ConstrainedWindowConstants::kCloseButtonPadding - kHeaderTopPadding,
76 0, 0, 0));
77 layout->AddView(close_button_);
78 99
79 set_background(views::Background::CreateSolidBackground( 100 set_background(views::Background::CreateSolidBackground(
80 ConstrainedWindow::GetBackgroundColor())); 101 ConstrainedWindow::GetBackgroundColor()));
81 102
82 // Client insets have no relation to header insets: 103 set_border(views::Border::CreateEmptyBorder(
83 // - The client insets are the distance from the window border to the client 104 ConstrainedWindowConstants::kClientTopPadding,
84 // view. 105 ConstrainedWindowConstants::kHorizontalPadding,
85 // - The header insets are the distance from the window border to the header 106 ConstrainedWindowConstants::kClientBottomPadding,
86 // elements. 107 ConstrainedWindowConstants::kHorizontalPadding));
87 //
88 // The NO_ISNETS consumers draw atop the views above.
89 if (client_insets == ConstrainedWindowViews::DEFAULT_INSETS) {
90 const int kTitleBuiltinBottomPadding = 4;
91 set_border(views::Border::CreateEmptyBorder(
92 ConstrainedWindowConstants::kClientTopPadding + kHeaderTopPadding +
93 std::max(close_button_->GetPreferredSize().height(),
94 title_label_->GetPreferredSize().height()) -
95 kTitleBuiltinBottomPadding,
96 ConstrainedWindowConstants::kHorizontalPadding,
97 ConstrainedWindowConstants::kClientBottomPadding,
98 ConstrainedWindowConstants::kHorizontalPadding));
99 }
100 } 108 }
101 109
102 ConstrainedWindowFrameSimple::~ConstrainedWindowFrameSimple() { 110 ConstrainedWindowFrameSimple::~ConstrainedWindowFrameSimple() {
103 } 111 }
104 112
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
105 gfx::Rect ConstrainedWindowFrameSimple::GetBoundsForClientView() const { 160 gfx::Rect ConstrainedWindowFrameSimple::GetBoundsForClientView() const {
106 return GetContentsBounds(); 161 gfx::Rect bounds(GetContentsBounds());
162 if (header_views_->header)
163 bounds.Inset(0, header_views_->header->GetPreferredSize().height(), 0, 0);
164 return bounds;
107 } 165 }
108 166
109 gfx::Rect ConstrainedWindowFrameSimple::GetWindowBoundsForClientBounds( 167 gfx::Rect ConstrainedWindowFrameSimple::GetWindowBoundsForClientBounds(
110 const gfx::Rect& client_bounds) const { 168 const gfx::Rect& client_bounds) const {
111 gfx::Rect bounds(client_bounds); 169 gfx::Rect bounds(client_bounds);
112 bounds.Inset(-GetInsets()); 170 bounds.Inset(-GetInsets());
113 bounds.set_width(std::max( 171 if (header_views_->header)
114 bounds.width(), 172 bounds.Inset(0, -header_views_->header->GetPreferredSize().height(), 0, 0);
115 ConstrainedWindowConstants::kHorizontalPadding +
116 2 * ConstrainedWindowConstants::kCloseButtonPadding +
117 title_label_->GetPreferredSize().width() +
118 close_button_->GetPreferredSize().width()));
119 return bounds; 173 return bounds;
120 } 174 }
121 175
122 int ConstrainedWindowFrameSimple::NonClientHitTest(const gfx::Point& point) { 176 int ConstrainedWindowFrameSimple::NonClientHitTest(const gfx::Point& point) {
123 if (!bounds().Contains(point)) 177 if (!bounds().Contains(point))
124 return HTNOWHERE; 178 return HTNOWHERE;
125 return HTCLIENT; 179 return HTCLIENT;
126 } 180 }
127 181
128 void ConstrainedWindowFrameSimple::GetWindowMask(const gfx::Size& size, 182 void ConstrainedWindowFrameSimple::GetWindowMask(const gfx::Size& size,
(...skipping 15 matching lines...) Expand all
144 window_mask->addRoundRect(rect, radii); 198 window_mask->addRoundRect(rect, radii);
145 } 199 }
146 200
147 void ConstrainedWindowFrameSimple::ResetWindowControls() { 201 void ConstrainedWindowFrameSimple::ResetWindowControls() {
148 } 202 }
149 203
150 void ConstrainedWindowFrameSimple::UpdateWindowIcon() { 204 void ConstrainedWindowFrameSimple::UpdateWindowIcon() {
151 } 205 }
152 206
153 void ConstrainedWindowFrameSimple::UpdateWindowTitle() { 207 void ConstrainedWindowFrameSimple::UpdateWindowTitle() {
154 title_label_->SetText(container_->widget_delegate()->GetWindowTitle()); 208 if (!header_views_->title_label)
209 return;
210
211 string16 text = container_->widget_delegate()->GetWindowTitle();
212 header_views_->title_label->SetText(text);
155 } 213 }
156 214
157 gfx::Size ConstrainedWindowFrameSimple::GetPreferredSize() { 215 gfx::Size ConstrainedWindowFrameSimple::GetPreferredSize() {
158 return GetWindowBoundsForClientBounds( 216 return container_->non_client_view()->GetWindowBoundsForClientBounds(
159 gfx::Rect(container_->client_view()->GetPreferredSize())).size(); 217 gfx::Rect(container_->client_view()->GetPreferredSize())).size();
160 } 218 }
161 219
162 void ConstrainedWindowFrameSimple::ButtonPressed(views::Button* sender, 220 void ConstrainedWindowFrameSimple::ButtonPressed(views::Button* sender,
163 const ui::Event& event) { 221 const ui::Event& event) {
164 if (sender == close_button_) 222 if (header_views_->close_button && sender == header_views_->close_button)
165 sender->GetWidget()->Close(); 223 sender->GetWidget()->Close();
166 } 224 }
225
226 views::ImageButton* ConstrainedWindowFrameSimple::CreateCloseButton() {
227 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
228 views::ImageButton* close_button = new views::ImageButton(this);
229 close_button->SetImage(views::CustomButton::BS_NORMAL,
230 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X));
231 close_button->SetImage(views::CustomButton::BS_HOT,
232 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER));
233 close_button->SetImage(views::CustomButton::BS_PUSHED,
234 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_PRESSED));
235 return close_button;
236 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/constrained_window_frame_simple.h ('k') | chrome/browser/ui/views/constrained_window_views.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698