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.Inset(kBottomSeparatorPadding, 0); | 202 int horizontal_padding = app_list::switches::IsExperimentalAppListEnabled() |
| 203 ? kExperimentalWindowPadding |
| 204 : kBottomSeparatorPadding; |
| 205 rect.Inset(horizontal_padding, 0); |
196 rect.set_y(rect.bottom() - kBottomSeparatorHeight); | 206 rect.set_y(rect.bottom() - kBottomSeparatorHeight); |
197 rect.set_height(kBottomSeparatorHeight); | 207 rect.set_height(kBottomSeparatorHeight); |
198 canvas->FillRect(rect, kTopSeparatorColor); | 208 canvas->FillRect(rect, kTopSeparatorColor); |
199 } | 209 } |
200 | 210 |
201 void FolderHeaderView::ContentsChanged(views::Textfield* sender, | 211 void FolderHeaderView::ContentsChanged(views::Textfield* sender, |
202 const base::string16& new_contents) { | 212 const base::string16& new_contents) { |
203 // Temporarily remove from observer to ignore data change caused by us. | 213 // Temporarily remove from observer to ignore data change caused by us. |
204 if (!folder_item_) | 214 if (!folder_item_) |
205 return; | 215 return; |
(...skipping 14 matching lines...) Expand all Loading... |
220 void FolderHeaderView::ButtonPressed(views::Button* sender, | 230 void FolderHeaderView::ButtonPressed(views::Button* sender, |
221 const ui::Event& event) { | 231 const ui::Event& event) { |
222 delegate_->NavigateBack(folder_item_, event); | 232 delegate_->NavigateBack(folder_item_, event); |
223 } | 233 } |
224 | 234 |
225 void FolderHeaderView::ItemNameChanged() { | 235 void FolderHeaderView::ItemNameChanged() { |
226 Update(); | 236 Update(); |
227 } | 237 } |
228 | 238 |
229 } // namespace app_list | 239 } // namespace app_list |
OLD | NEW |