OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/app_list/views/folder_header_view.h" | 5 #include "ui/app_list/views/folder_header_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "ui/app_list/app_list_constants.h" | 10 #include "ui/app_list/app_list_constants.h" |
11 #include "ui/app_list/app_list_folder_item.h" | 11 #include "ui/app_list/app_list_folder_item.h" |
12 #include "ui/app_list/app_list_switches.h" | |
12 #include "ui/app_list/views/app_list_folder_view.h" | 13 #include "ui/app_list/views/app_list_folder_view.h" |
13 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
14 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
15 #include "ui/resources/grit/ui_resources.h" | 16 #include "ui/resources/grit/ui_resources.h" |
16 #include "ui/strings/grit/ui_strings.h" | 17 #include "ui/strings/grit/ui_strings.h" |
17 #include "ui/views/border.h" | 18 #include "ui/views/border.h" |
18 #include "ui/views/controls/button/image_button.h" | 19 #include "ui/views/controls/button/image_button.h" |
19 #include "ui/views/controls/textfield/textfield.h" | 20 #include "ui/views/controls/textfield/textfield.h" |
20 #include "ui/views/painter.h" | 21 #include "ui/views/painter.h" |
21 | 22 |
22 namespace app_list { | 23 namespace app_list { |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 const int kPreferredWidth = 360; | 27 const int kPreferredWidth = 360; |
27 const int kPreferredHeight = 48; | 28 const int kPreferredHeight = 48; |
28 const int kIconDimension = 24; | 29 const int kIconDimension = 24; |
29 const int kPadding = 14; | 30 const int kBackButtonPadding = 14; |
30 const int kBottomSeparatorPadding = 9; | 31 const int kBottomSeparatorPadding = 9; // Non-experimental app list only. |
31 const int kBottomSeparatorHeight = 1; | 32 const int kBottomSeparatorHeight = 1; |
32 const int kMaxFolderNameWidth = 300; | 33 const int kMaxFolderNameWidth = 300; |
33 | 34 |
34 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); | 35 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); |
35 | 36 |
36 } // namespace | 37 } // namespace |
37 | 38 |
38 class FolderHeaderView::FolderNameView : public views::Textfield { | 39 class FolderHeaderView::FolderNameView : public views::Textfield { |
39 public: | 40 public: |
40 FolderNameView() { | 41 FolderNameView() { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 gfx::Size FolderHeaderView::GetPreferredSize() const { | 152 gfx::Size FolderHeaderView::GetPreferredSize() const { |
152 return gfx::Size(kPreferredWidth, kPreferredHeight); | 153 return gfx::Size(kPreferredWidth, kPreferredHeight); |
153 } | 154 } |
154 | 155 |
155 void FolderHeaderView::Layout() { | 156 void FolderHeaderView::Layout() { |
156 gfx::Rect rect(GetContentsBounds()); | 157 gfx::Rect rect(GetContentsBounds()); |
157 if (rect.IsEmpty()) | 158 if (rect.IsEmpty()) |
158 return; | 159 return; |
159 | 160 |
160 gfx::Rect back_bounds(rect); | 161 gfx::Rect back_bounds(rect); |
161 back_bounds.set_width(kIconDimension + 2 * kPadding); | 162 back_bounds.set_width(kIconDimension + 2 * kBackButtonPadding); |
163 if (app_list::switches::IsExperimentalAppListEnabled()) { | |
164 // Align the left edge of the button image with the left margin of the | |
165 // launcher window. Note that this means the physical button dimensions | |
166 // extends slightly into the margin. | |
167 back_bounds.set_x(kExperimentalWindowPadding - kBackButtonPadding); | |
168 } | |
162 back_button_->SetBoundsRect(back_bounds); | 169 back_button_->SetBoundsRect(back_bounds); |
163 | 170 |
164 gfx::Rect text_bounds(rect); | 171 gfx::Rect text_bounds(rect); |
165 base::string16 text = folder_item_ && !folder_item_->name().empty() | 172 base::string16 text = folder_item_ && !folder_item_->name().empty() |
166 ? base::UTF8ToUTF16(folder_item_->name()) | 173 ? base::UTF8ToUTF16(folder_item_->name()) |
167 : folder_name_placeholder_text_; | 174 : folder_name_placeholder_text_; |
168 int text_width = | 175 int text_width = |
169 gfx::Canvas::GetStringWidth(text, folder_name_view_->GetFontList()) + | 176 gfx::Canvas::GetStringWidth(text, folder_name_view_->GetFontList()) + |
170 folder_name_view_->GetCaretBounds().width() + | 177 folder_name_view_->GetCaretBounds().width() + |
171 folder_name_view_->GetInsets().width(); | 178 folder_name_view_->GetInsets().width(); |
(...skipping 13 matching lines...) Expand all Loading... | |
185 } | 192 } |
186 | 193 |
187 void FolderHeaderView::OnPaint(gfx::Canvas* canvas) { | 194 void FolderHeaderView::OnPaint(gfx::Canvas* canvas) { |
188 views::View::OnPaint(canvas); | 195 views::View::OnPaint(canvas); |
189 | 196 |
190 gfx::Rect rect(GetContentsBounds()); | 197 gfx::Rect rect(GetContentsBounds()); |
191 if (rect.IsEmpty() || !folder_name_visible_) | 198 if (rect.IsEmpty() || !folder_name_visible_) |
192 return; | 199 return; |
193 | 200 |
194 // Draw bottom separator line. | 201 // Draw bottom separator line. |
195 rect.set_x(kBottomSeparatorPadding); | 202 int horizontal_padding = app_list::switches::IsExperimentalAppListEnabled() |
203 ? kExperimentalWindowPadding | |
204 : kBottomSeparatorPadding; | |
205 rect.set_x(horizontal_padding); | |
196 rect.set_y(rect.y() + rect.height() - kBottomSeparatorHeight); | 206 rect.set_y(rect.y() + rect.height() - kBottomSeparatorHeight); |
calamity
2014/09/19 05:10:56
Use rect.bottom().
Matt Giuca
2014/09/19 09:56:05
Done.
| |
197 rect.set_width(rect.width() - kBottomSeparatorPadding * 2); | 207 rect.set_width(rect.width() - horizontal_padding * 2); |
calamity
2014/09/19 05:10:56
Use Rect::Inset().
Matt Giuca
2014/09/19 09:56:05
Done.
| |
198 rect.set_height(kBottomSeparatorHeight); | 208 rect.set_height(kBottomSeparatorHeight); |
199 canvas->FillRect(rect, kTopSeparatorColor); | 209 canvas->FillRect(rect, kTopSeparatorColor); |
200 } | 210 } |
201 | 211 |
202 void FolderHeaderView::ContentsChanged(views::Textfield* sender, | 212 void FolderHeaderView::ContentsChanged(views::Textfield* sender, |
203 const base::string16& new_contents) { | 213 const base::string16& new_contents) { |
204 // Temporarily remove from observer to ignore data change caused by us. | 214 // Temporarily remove from observer to ignore data change caused by us. |
205 if (!folder_item_) | 215 if (!folder_item_) |
206 return; | 216 return; |
207 | 217 |
(...skipping 13 matching lines...) Expand all Loading... | |
221 void FolderHeaderView::ButtonPressed(views::Button* sender, | 231 void FolderHeaderView::ButtonPressed(views::Button* sender, |
222 const ui::Event& event) { | 232 const ui::Event& event) { |
223 delegate_->NavigateBack(folder_item_, event); | 233 delegate_->NavigateBack(folder_item_, event); |
224 } | 234 } |
225 | 235 |
226 void FolderHeaderView::ItemNameChanged() { | 236 void FolderHeaderView::ItemNameChanged() { |
227 Update(); | 237 Update(); |
228 } | 238 } |
229 | 239 |
230 } // namespace app_list | 240 } // namespace app_list |
OLD | NEW |