| 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/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "ui/views/controls/textfield/textfield.h" | 21 #include "ui/views/controls/textfield/textfield.h" |
| 22 #include "ui/views/focus/focus_manager.h" | 22 #include "ui/views/focus/focus_manager.h" |
| 23 #include "ui/views/painter.h" | 23 #include "ui/views/painter.h" |
| 24 | 24 |
| 25 namespace app_list { | 25 namespace app_list { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 const int kPreferredWidth = 360; | 29 const int kPreferredWidth = 360; |
| 30 const int kPreferredHeight = 48; | 30 const int kPreferredHeight = 48; |
| 31 const int kIconDimension = 24; | |
| 32 const int kBackButtonPadding = 14; | |
| 33 const int kBottomSeparatorPadding = 9; // Non-experimental app list only. | |
| 34 const int kBottomSeparatorHeight = 1; | 31 const int kBottomSeparatorHeight = 1; |
| 35 const int kMaxFolderNameWidth = 300; | 32 const int kMaxFolderNameWidth = 300; |
| 36 | 33 |
| 37 } // namespace | 34 } // namespace |
| 38 | 35 |
| 39 class FolderHeaderView::FolderNameView : public views::Textfield { | 36 class FolderHeaderView::FolderNameView : public views::Textfield { |
| 40 public: | 37 public: |
| 41 FolderNameView() { | 38 FolderNameView() { |
| 42 SetBorder(views::Border::CreateEmptyBorder(1, 1, 1, 1)); | 39 SetBorder(views::Border::CreateEmptyBorder(1, 1, 1, 1)); |
| 43 SetTextColor(kFolderTitleColor); | 40 SetTextColor(kFolderTitleColor); |
| 44 } | 41 } |
| 45 | 42 |
| 46 ~FolderNameView() override {} | 43 ~FolderNameView() override {} |
| 47 | 44 |
| 48 private: | 45 private: |
| 49 DISALLOW_COPY_AND_ASSIGN(FolderNameView); | 46 DISALLOW_COPY_AND_ASSIGN(FolderNameView); |
| 50 }; | 47 }; |
| 51 | 48 |
| 52 FolderHeaderView::FolderHeaderView(FolderHeaderViewDelegate* delegate) | 49 FolderHeaderView::FolderHeaderView(FolderHeaderViewDelegate* delegate) |
| 53 : folder_item_(nullptr), | 50 : folder_item_(nullptr), |
| 54 back_button_(nullptr), | |
| 55 folder_name_view_(new FolderNameView), | 51 folder_name_view_(new FolderNameView), |
| 56 folder_name_placeholder_text_( | 52 folder_name_placeholder_text_( |
| 57 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | 53 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( |
| 58 IDS_APP_LIST_FOLDER_NAME_PLACEHOLDER)), | 54 IDS_APP_LIST_FOLDER_NAME_PLACEHOLDER)), |
| 59 delegate_(delegate), | 55 delegate_(delegate), |
| 60 folder_name_visible_(true) { | 56 folder_name_visible_(true) { |
| 61 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 57 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 62 if (!app_list::switches::IsExperimentalAppListEnabled()) { | |
| 63 back_button_ = new views::ImageButton(this); | |
| 64 back_button_->SetImage( | |
| 65 views::ImageButton::STATE_NORMAL, | |
| 66 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); | |
| 67 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | |
| 68 views::ImageButton::ALIGN_MIDDLE); | |
| 69 AddChildView(back_button_); | |
| 70 back_button_->SetFocusForPlatform(); | |
| 71 back_button_->set_request_focus_on_press(true); | |
| 72 back_button_->SetAccessibleName( | |
| 73 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | |
| 74 IDS_APP_LIST_FOLDER_CLOSE_FOLDER_ACCESSIBILE_NAME)); | |
| 75 } | |
| 76 | |
| 77 folder_name_view_->SetFontList( | 58 folder_name_view_->SetFontList( |
| 78 rb.GetFontList(ui::ResourceBundle::MediumFont)); | 59 rb.GetFontList(ui::ResourceBundle::MediumFont)); |
| 79 folder_name_view_->set_placeholder_text_color(kFolderTitleHintTextColor); | 60 folder_name_view_->set_placeholder_text_color(kFolderTitleHintTextColor); |
| 80 folder_name_view_->set_placeholder_text(folder_name_placeholder_text_); | 61 folder_name_view_->set_placeholder_text(folder_name_placeholder_text_); |
| 81 folder_name_view_->SetBorder(views::Border::NullBorder()); | 62 folder_name_view_->SetBorder(views::Border::NullBorder()); |
| 82 folder_name_view_->SetBackgroundColor(kContentsBackgroundColor); | 63 folder_name_view_->SetBackgroundColor(kContentsBackgroundColor); |
| 83 folder_name_view_->set_controller(this); | 64 folder_name_view_->set_controller(this); |
| 84 AddChildView(folder_name_view_); | 65 AddChildView(folder_name_view_); |
| 85 } | 66 } |
| 86 | 67 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 145 |
| 165 gfx::Size FolderHeaderView::GetPreferredSize() const { | 146 gfx::Size FolderHeaderView::GetPreferredSize() const { |
| 166 return gfx::Size(kPreferredWidth, kPreferredHeight); | 147 return gfx::Size(kPreferredWidth, kPreferredHeight); |
| 167 } | 148 } |
| 168 | 149 |
| 169 void FolderHeaderView::Layout() { | 150 void FolderHeaderView::Layout() { |
| 170 gfx::Rect rect(GetContentsBounds()); | 151 gfx::Rect rect(GetContentsBounds()); |
| 171 if (rect.IsEmpty()) | 152 if (rect.IsEmpty()) |
| 172 return; | 153 return; |
| 173 | 154 |
| 174 if (!switches::IsExperimentalAppListEnabled()) { | |
| 175 gfx::Rect back_bounds; | |
| 176 DCHECK(back_button_); | |
| 177 back_bounds = rect; | |
| 178 back_bounds.set_width(kIconDimension + 2 * kBackButtonPadding); | |
| 179 back_button_->SetBoundsRect(back_bounds); | |
| 180 } | |
| 181 | |
| 182 gfx::Rect text_bounds(rect); | 155 gfx::Rect text_bounds(rect); |
| 183 base::string16 text = folder_item_ && !folder_item_->name().empty() | 156 base::string16 text = folder_item_ && !folder_item_->name().empty() |
| 184 ? base::UTF8ToUTF16(folder_item_->name()) | 157 ? base::UTF8ToUTF16(folder_item_->name()) |
| 185 : folder_name_placeholder_text_; | 158 : folder_name_placeholder_text_; |
| 186 int text_width = | 159 int text_width = |
| 187 gfx::Canvas::GetStringWidth(text, folder_name_view_->GetFontList()) + | 160 gfx::Canvas::GetStringWidth(text, folder_name_view_->GetFontList()) + |
| 188 folder_name_view_->GetCaretBounds().width() + | 161 folder_name_view_->GetCaretBounds().width() + |
| 189 folder_name_view_->GetInsets().width(); | 162 folder_name_view_->GetInsets().width(); |
| 190 text_width = std::min(text_width, kMaxFolderNameWidth); | 163 text_width = std::min(text_width, kMaxFolderNameWidth); |
| 191 text_bounds.set_x(rect.x() + (rect.width() - text_width) / 2); | 164 text_bounds.set_x(rect.x() + (rect.width() - text_width) / 2); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 203 } | 176 } |
| 204 | 177 |
| 205 void FolderHeaderView::OnPaint(gfx::Canvas* canvas) { | 178 void FolderHeaderView::OnPaint(gfx::Canvas* canvas) { |
| 206 views::View::OnPaint(canvas); | 179 views::View::OnPaint(canvas); |
| 207 | 180 |
| 208 gfx::Rect rect(GetContentsBounds()); | 181 gfx::Rect rect(GetContentsBounds()); |
| 209 if (rect.IsEmpty() || !folder_name_visible_) | 182 if (rect.IsEmpty() || !folder_name_visible_) |
| 210 return; | 183 return; |
| 211 | 184 |
| 212 // Draw bottom separator line. | 185 // Draw bottom separator line. |
| 213 int horizontal_padding = app_list::switches::IsExperimentalAppListEnabled() | 186 rect.Inset(kAppsGridPadding, 0); |
| 214 ? kExperimentalAppsGridPadding | |
| 215 : kBottomSeparatorPadding; | |
| 216 rect.Inset(horizontal_padding, 0); | |
| 217 rect.set_y(rect.bottom() - kBottomSeparatorHeight); | 187 rect.set_y(rect.bottom() - kBottomSeparatorHeight); |
| 218 rect.set_height(kBottomSeparatorHeight); | 188 rect.set_height(kBottomSeparatorHeight); |
| 219 canvas->FillRect(rect, kTopSeparatorColor); | 189 canvas->FillRect(rect, kTopSeparatorColor); |
| 220 } | 190 } |
| 221 | 191 |
| 222 void FolderHeaderView::ContentsChanged(views::Textfield* sender, | 192 void FolderHeaderView::ContentsChanged(views::Textfield* sender, |
| 223 const base::string16& new_contents) { | 193 const base::string16& new_contents) { |
| 224 // Temporarily remove from observer to ignore data change caused by us. | 194 // Temporarily remove from observer to ignore data change caused by us. |
| 225 if (!folder_item_) | 195 if (!folder_item_) |
| 226 return; | 196 return; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 241 void FolderHeaderView::ButtonPressed(views::Button* sender, | 211 void FolderHeaderView::ButtonPressed(views::Button* sender, |
| 242 const ui::Event& event) { | 212 const ui::Event& event) { |
| 243 delegate_->NavigateBack(folder_item_, event); | 213 delegate_->NavigateBack(folder_item_, event); |
| 244 } | 214 } |
| 245 | 215 |
| 246 void FolderHeaderView::ItemNameChanged() { | 216 void FolderHeaderView::ItemNameChanged() { |
| 247 Update(); | 217 Update(); |
| 248 } | 218 } |
| 249 | 219 |
| 250 } // namespace app_list | 220 } // namespace app_list |
| OLD | NEW |