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 "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
9 #include "grit/ui_strings.h" | 9 #include "grit/ui_strings.h" |
10 #include "ui/app_list/app_list_constants.h" | 10 #include "ui/app_list/app_list_constants.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 } | 53 } |
54 | 54 |
55 private: | 55 private: |
56 DISALLOW_COPY_AND_ASSIGN(FolderNameView); | 56 DISALLOW_COPY_AND_ASSIGN(FolderNameView); |
57 }; | 57 }; |
58 | 58 |
59 FolderHeaderView::FolderHeaderView(FolderHeaderViewDelegate* delegate) | 59 FolderHeaderView::FolderHeaderView(FolderHeaderViewDelegate* delegate) |
60 : folder_item_(NULL), | 60 : folder_item_(NULL), |
61 back_button_(new views::ImageButton(this)), | 61 back_button_(new views::ImageButton(this)), |
62 folder_name_view_(new FolderNameView), | 62 folder_name_view_(new FolderNameView), |
63 delegate_(delegate) { | 63 delegate_(delegate), |
| 64 folder_name_visible_(true) { |
64 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 65 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
65 back_button_->SetImage(views::ImageButton::STATE_NORMAL, | 66 back_button_->SetImage(views::ImageButton::STATE_NORMAL, |
66 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); | 67 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); |
67 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 68 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
68 views::ImageButton::ALIGN_MIDDLE); | 69 views::ImageButton::ALIGN_MIDDLE); |
69 AddChildView(back_button_); | 70 AddChildView(back_button_); |
70 | 71 |
71 folder_name_view_->SetFontList( | 72 folder_name_view_->SetFontList( |
72 rb.GetFontList(ui::ResourceBundle::MediumFont)); | 73 rb.GetFontList(ui::ResourceBundle::MediumFont)); |
73 folder_name_view_->set_placeholder_text_color(kHintTextColor); | 74 folder_name_view_->set_placeholder_text_color(kHintTextColor); |
(...skipping 15 matching lines...) Expand all Loading... |
89 folder_item_->RemoveObserver(this); | 90 folder_item_->RemoveObserver(this); |
90 | 91 |
91 folder_item_ = folder_item; | 92 folder_item_ = folder_item; |
92 if (!folder_item_) | 93 if (!folder_item_) |
93 return; | 94 return; |
94 folder_item_->AddObserver(this); | 95 folder_item_->AddObserver(this); |
95 | 96 |
96 Update(); | 97 Update(); |
97 } | 98 } |
98 | 99 |
| 100 void FolderHeaderView::UpdateFolderNameVisibility(bool visible) { |
| 101 folder_name_visible_ = visible; |
| 102 Update(); |
| 103 SchedulePaint(); |
| 104 } |
| 105 |
| 106 void FolderHeaderView::OnFolderItemRemoved() { |
| 107 folder_item_ = NULL; |
| 108 } |
| 109 |
99 void FolderHeaderView::Update() { | 110 void FolderHeaderView::Update() { |
100 if (!folder_item_) | 111 if (!folder_item_) |
101 return; | 112 return; |
102 | 113 |
103 folder_name_view_->SetText(base::UTF8ToUTF16(folder_item_->title())); | 114 folder_name_view_->SetVisible(folder_name_visible_); |
| 115 if (folder_name_visible_) |
| 116 folder_name_view_->SetText(base::UTF8ToUTF16(folder_item_->title())); |
104 } | 117 } |
105 | 118 |
106 gfx::Size FolderHeaderView::GetPreferredSize() { | 119 gfx::Size FolderHeaderView::GetPreferredSize() { |
107 return gfx::Size(kPreferredWidth, kPreferredHeight); | 120 return gfx::Size(kPreferredWidth, kPreferredHeight); |
108 } | 121 } |
109 | 122 |
110 void FolderHeaderView::Layout() { | 123 void FolderHeaderView::Layout() { |
111 gfx::Rect rect(GetContentsBounds()); | 124 gfx::Rect rect(GetContentsBounds()); |
112 if (rect.IsEmpty()) | 125 if (rect.IsEmpty()) |
113 return; | 126 return; |
114 | 127 |
115 gfx::Rect back_bounds(rect); | 128 gfx::Rect back_bounds(rect); |
116 back_bounds.set_width(kIconDimension + 2 * kPadding); | 129 back_bounds.set_width(kIconDimension + 2 * kPadding); |
117 back_button_->SetBoundsRect(back_bounds); | 130 back_button_->SetBoundsRect(back_bounds); |
118 | 131 |
119 gfx::Rect text_bounds(rect); | 132 gfx::Rect text_bounds(rect); |
120 int text_width = folder_name_view_->GetPreferredSize().width(); | 133 int text_width = folder_name_view_->GetPreferredSize().width(); |
121 text_bounds.set_x(back_bounds.x() + (rect.width() - text_width) / 2); | 134 text_bounds.set_x(back_bounds.x() + (rect.width() - text_width) / 2); |
122 text_bounds.set_width(text_width); | 135 text_bounds.set_width(text_width); |
123 text_bounds.ClampToCenteredSize(gfx::Size(text_bounds.width(), | 136 text_bounds.ClampToCenteredSize(gfx::Size(text_bounds.width(), |
124 folder_name_view_->GetPreferredSize().height())); | 137 folder_name_view_->GetPreferredSize().height())); |
125 folder_name_view_->SetBoundsRect(text_bounds); | 138 folder_name_view_->SetBoundsRect(text_bounds); |
126 } | 139 } |
127 | 140 |
128 void FolderHeaderView::OnPaint(gfx::Canvas* canvas) { | 141 void FolderHeaderView::OnPaint(gfx::Canvas* canvas) { |
129 views::View::OnPaint(canvas); | 142 views::View::OnPaint(canvas); |
130 | 143 |
131 gfx::Rect rect(GetContentsBounds()); | 144 gfx::Rect rect(GetContentsBounds()); |
132 if (rect.IsEmpty()) | 145 if (rect.IsEmpty() || !folder_name_visible_) |
133 return; | 146 return; |
134 | 147 |
135 // Draw bottom separator line. | 148 // Draw bottom separator line. |
136 rect.set_x((rect.width() - kBottomSeparatorWidth) / 2 + rect.x()); | 149 rect.set_x((rect.width() - kBottomSeparatorWidth) / 2 + rect.x()); |
137 rect.set_y(rect.y() + rect.height() - kBottomSeparatorHeight); | 150 rect.set_y(rect.y() + rect.height() - kBottomSeparatorHeight); |
138 rect.set_width(kBottomSeparatorWidth); | 151 rect.set_width(kBottomSeparatorWidth); |
139 rect.set_height(kBottomSeparatorHeight); | 152 rect.set_height(kBottomSeparatorHeight); |
140 canvas->FillRect(rect, kTopSeparatorColor); | 153 canvas->FillRect(rect, kTopSeparatorColor); |
141 } | 154 } |
142 | 155 |
(...skipping 25 matching lines...) Expand all Loading... |
168 } | 181 } |
169 | 182 |
170 void FolderHeaderView::ItemIsInstallingChanged() { | 183 void FolderHeaderView::ItemIsInstallingChanged() { |
171 } | 184 } |
172 | 185 |
173 void FolderHeaderView::ItemPercentDownloadedChanged() { | 186 void FolderHeaderView::ItemPercentDownloadedChanged() { |
174 } | 187 } |
175 | 188 |
176 } // namespace app_list | 189 } // namespace app_list |
177 | 190 |
OLD | NEW |