OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/app_list/views/folder_header_view.h" | |
6 | |
7 #include "base/strings/utf_string_conversions.h" | |
8 #include "grit/ui_resources.h" | |
9 #include "grit/ui_strings.h" | |
10 #include "ui/app_list/app_list_constants.h" | |
11 #include "ui/app_list/app_list_folder_item.h" | |
12 #include "ui/app_list/views/app_list_folder_view.h" | |
13 #include "ui/base/resource/resource_bundle.h" | |
14 #include "ui/gfx/canvas.h" | |
15 #include "ui/views/controls/button/image_button.h" | |
16 #include "ui/views/controls/textfield/textfield.h" | |
17 | |
18 namespace app_list { | |
19 | |
20 namespace { | |
21 | |
22 const int kPreferredWidth = 360; | |
23 const int kPreferredHeight = 48; | |
24 const int kIconDimension = 32; | |
25 const int kPadding = 14; | |
26 const int kFolderNameWidth = 150; | |
27 const int kFolderNameHeight = 30; | |
28 const int kBottomSeparatorWidth = 380; | |
29 const int kBottomSeparatorHeight = 1; | |
30 | |
31 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); | |
32 | |
33 } // namespace | |
34 | |
35 class FolderHeaderView::FolderNameView : public views::Textfield { | |
36 public: | |
37 FolderNameView() { | |
38 set_border(views::Border::CreateEmptyBorder(1, 1, 1, 1)); | |
39 } | |
40 | |
41 virtual ~FolderNameView() { | |
42 } | |
43 | |
44 // Overridden from views::View: | |
45 virtual gfx::Size GetPreferredSize() OVERRIDE { | |
46 return gfx::Size(kFolderNameWidth, kFolderNameHeight); | |
47 } | |
48 | |
49 virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE { | |
50 const SkColor kFocusBorderColor = SkColorSetRGB(64, 128, 250); | |
51 if (HasFocus() && focusable()) { | |
52 gfx::Rect rect = GetLocalBounds(); | |
53 rect.Inset(0, 0, 1, 1); | |
54 canvas->DrawRect(rect, kFocusBorderColor); | |
55 } | |
56 } | |
57 | |
58 private: | |
59 DISALLOW_COPY_AND_ASSIGN(FolderNameView); | |
60 }; | |
61 | |
62 FolderHeaderView::FolderHeaderView(FolderHeaderViewDelegate* delegate) | |
63 : folder_item_(NULL), | |
64 back_button_(new views::ImageButton(this)), | |
65 folder_name_view_(new FolderNameView), | |
66 delegate_(delegate) { | |
67 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
68 back_button_->SetImage(views::ImageButton::STATE_NORMAL, | |
69 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); | |
70 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | |
71 views::ImageButton::ALIGN_MIDDLE); | |
72 AddChildView(back_button_); | |
73 | |
74 folder_name_view_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); | |
75 folder_name_view_->set_placeholder_text_color(kHintTextColor); | |
76 folder_name_view_->set_placeholder_text( | |
77 rb.GetLocalizedString(IDS_APP_LIST_FOLDER_NAME_PLACEHOLDER)); | |
78 folder_name_view_->RemoveBorder(); | |
79 folder_name_view_->SetBackgroundColor(kContentsBackgroundColor); | |
80 folder_name_view_->SetController(this); | |
81 AddChildView(folder_name_view_); | |
82 } | |
83 | |
84 FolderHeaderView::~FolderHeaderView() { | |
85 if (folder_item_) | |
86 folder_item_->RemoveObserver(this); | |
87 } | |
88 | |
89 void FolderHeaderView::SetFolderItem(AppListFolderItem* folder_item) { | |
90 if (folder_item_) | |
91 folder_item_->RemoveObserver(this); | |
92 | |
93 folder_item_ = folder_item; | |
94 if (!folder_item_) | |
95 return; | |
96 folder_item_->AddObserver(this); | |
97 | |
98 Update(); | |
99 } | |
100 | |
101 void FolderHeaderView::Update() { | |
102 if (!folder_item_) | |
103 return; | |
104 | |
105 folder_name_view_->SetText(UTF8ToUTF16(folder_item_->title())); | |
106 } | |
107 | |
108 gfx::Size FolderHeaderView::GetPreferredSize() { | |
109 return gfx::Size(kPreferredWidth, kPreferredHeight); | |
110 } | |
111 | |
112 void FolderHeaderView::Layout() { | |
113 gfx::Rect rect(GetContentsBounds()); | |
114 if (rect.IsEmpty()) | |
115 return; | |
116 | |
117 gfx::Rect back_bounds(rect); | |
118 back_bounds.set_width(kIconDimension + 2 * kPadding); | |
119 back_button_->SetBoundsRect(back_bounds); | |
120 | |
121 gfx::Rect text_bounds(rect); | |
122 int text_width = folder_name_view_->GetPreferredSize().width(); | |
123 text_bounds.set_x(back_bounds.x() + (rect.width() - text_width) / 2); | |
124 text_bounds.set_width(text_width); | |
125 text_bounds.ClampToCenteredSize(gfx::Size(text_bounds.width(), | |
126 folder_name_view_->GetPreferredSize().height())); | |
127 folder_name_view_->SetBoundsRect(text_bounds); | |
128 } | |
129 | |
130 void FolderHeaderView::OnPaint(gfx::Canvas* canvas) { | |
131 views::View::OnPaint(canvas); | |
132 | |
133 gfx::Rect rect(GetContentsBounds()); | |
134 if (rect.IsEmpty()) | |
135 return; | |
stevenjb
2013/10/22 18:34:27
indentation
jennyz
2013/10/22 18:55:36
Done.
| |
136 | |
137 // Draw bottom separator line. | |
138 rect.set_x((rect.width() - kBottomSeparatorWidth) / 2 + rect.x()); | |
139 rect.set_y(rect.y() + rect.height() - kBottomSeparatorHeight); | |
140 rect.set_width(kBottomSeparatorWidth); | |
141 rect.set_height(kBottomSeparatorHeight); | |
142 canvas->FillRect(rect, kTopSeparatorColor); | |
143 } | |
144 | |
145 void FolderHeaderView::ContentsChanged(views::Textfield* sender, | |
146 const base::string16& new_contents) { | |
147 // Temporarily remove from observer to ignore data change caused by us. | |
148 if (!folder_item_) | |
149 return; | |
150 | |
151 folder_item_->RemoveObserver(this); | |
152 std::string name = UTF16ToUTF8(folder_name_view_->text()); | |
153 folder_item_->SetTitleAndFullName(name, name); | |
154 folder_item_->AddObserver(this); | |
155 } | |
156 | |
157 void FolderHeaderView::ButtonPressed(views::Button* sender, | |
158 const ui::Event& event) { | |
159 delegate_->NavigateBack(folder_item_, event); | |
160 } | |
161 | |
162 void FolderHeaderView::ItemIconChanged() { | |
163 } | |
164 | |
165 void FolderHeaderView::ItemTitleChanged() { | |
166 Update(); | |
167 } | |
168 | |
169 void FolderHeaderView::ItemHighlightedChanged() { | |
170 } | |
171 | |
172 void FolderHeaderView::ItemIsInstallingChanged() { | |
173 } | |
174 | |
175 void FolderHeaderView::ItemPercentDownloadedChanged() { | |
176 } | |
177 | |
178 } // namespace app_list | |
179 | |
OLD | NEW |