| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "ash/session_state_delegate.h" | 7 #include "ash/session_state_delegate.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell/example_factory.h" | 9 #include "ash/shell/example_factory.h" |
| 10 #include "ash/shell/toplevel_window.h" | 10 #include "ash/shell/toplevel_window.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "ui/gfx/font_list.h" | 28 #include "ui/gfx/font_list.h" |
| 29 #include "ui/gfx/geometry/rect.h" | 29 #include "ui/gfx/geometry/rect.h" |
| 30 #include "ui/gfx/image/image_skia.h" | 30 #include "ui/gfx/image/image_skia.h" |
| 31 #include "ui/views/examples/examples_window_with_content.h" | 31 #include "ui/views/examples/examples_window_with_content.h" |
| 32 | 32 |
| 33 namespace ash { | 33 namespace ash { |
| 34 namespace shell { | 34 namespace shell { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 // WindowTypeLauncherItem is an app item of app list. It carries a window | 38 // WindowTypeShelfItem is an app item of app list. It carries a window |
| 39 // launch type and launches corresponding example window when activated. | 39 // launch type and launches corresponding example window when activated. |
| 40 class WindowTypeLauncherItem : public app_list::AppListItem { | 40 class WindowTypeShelfItem : public app_list::AppListItem { |
| 41 public: | 41 public: |
| 42 enum Type { | 42 enum Type { |
| 43 TOPLEVEL_WINDOW = 0, | 43 TOPLEVEL_WINDOW = 0, |
| 44 NON_RESIZABLE_WINDOW, | 44 NON_RESIZABLE_WINDOW, |
| 45 LOCK_SCREEN, | 45 LOCK_SCREEN, |
| 46 WIDGETS_WINDOW, | 46 WIDGETS_WINDOW, |
| 47 EXAMPLES_WINDOW, | 47 EXAMPLES_WINDOW, |
| 48 LAST_TYPE, | 48 LAST_TYPE, |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 explicit WindowTypeLauncherItem(const std::string& id, Type type) | 51 explicit WindowTypeShelfItem(const std::string& id, Type type) |
| 52 : app_list::AppListItem(id), | 52 : app_list::AppListItem(id), |
| 53 type_(type) { | 53 type_(type) { |
| 54 std::string title(GetTitle(type)); | 54 std::string title(GetTitle(type)); |
| 55 SetIcon(GetIcon(type), false); | 55 SetIcon(GetIcon(type), false); |
| 56 SetTitleAndFullName(title, title); | 56 SetTitleAndFullName(title, title); |
| 57 } | 57 } |
| 58 | 58 |
| 59 static gfx::ImageSkia GetIcon(Type type) { | 59 static gfx::ImageSkia GetIcon(Type type) { |
| 60 static const SkColor kColors[] = { | 60 static const SkColor kColors[] = { |
| 61 SK_ColorRED, | 61 SK_ColorRED, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } | 138 } |
| 139 | 139 |
| 140 // AppListItem | 140 // AppListItem |
| 141 virtual void Activate(int event_flags) OVERRIDE { | 141 virtual void Activate(int event_flags) OVERRIDE { |
| 142 ActivateItem(type_, event_flags); | 142 ActivateItem(type_, event_flags); |
| 143 } | 143 } |
| 144 | 144 |
| 145 private: | 145 private: |
| 146 Type type_; | 146 Type type_; |
| 147 | 147 |
| 148 DISALLOW_COPY_AND_ASSIGN(WindowTypeLauncherItem); | 148 DISALLOW_COPY_AND_ASSIGN(WindowTypeShelfItem); |
| 149 }; | 149 }; |
| 150 | 150 |
| 151 // ExampleSearchResult is an app list search result. It provides what icon to | 151 // ExampleSearchResult is an app list search result. It provides what icon to |
| 152 // show, what should title and details text look like. It also carries the | 152 // show, what should title and details text look like. It also carries the |
| 153 // matching window launch type so that AppListViewDelegate knows how to open | 153 // matching window launch type so that AppListViewDelegate knows how to open |
| 154 // it. | 154 // it. |
| 155 class ExampleSearchResult : public app_list::SearchResult { | 155 class ExampleSearchResult : public app_list::SearchResult { |
| 156 public: | 156 public: |
| 157 ExampleSearchResult(WindowTypeLauncherItem::Type type, | 157 ExampleSearchResult(WindowTypeShelfItem::Type type, |
| 158 const base::string16& query) | 158 const base::string16& query) |
| 159 : type_(type) { | 159 : type_(type) { |
| 160 SetIcon(WindowTypeLauncherItem::GetIcon(type_)); | 160 SetIcon(WindowTypeShelfItem::GetIcon(type_)); |
| 161 | 161 |
| 162 base::string16 title = | 162 base::string16 title = |
| 163 base::UTF8ToUTF16(WindowTypeLauncherItem::GetTitle(type_)); | 163 base::UTF8ToUTF16(WindowTypeShelfItem::GetTitle(type_)); |
| 164 set_title(title); | 164 set_title(title); |
| 165 | 165 |
| 166 Tags title_tags; | 166 Tags title_tags; |
| 167 const size_t match_len = query.length(); | 167 const size_t match_len = query.length(); |
| 168 | 168 |
| 169 // Highlight matching parts in title with bold. | 169 // Highlight matching parts in title with bold. |
| 170 // Note the following is not a proper way to handle i18n string. | 170 // Note the following is not a proper way to handle i18n string. |
| 171 title = base::i18n::ToLower(title); | 171 title = base::i18n::ToLower(title); |
| 172 size_t match_start = title.find(query); | 172 size_t match_start = title.find(query); |
| 173 while (match_start != base::string16::npos) { | 173 while (match_start != base::string16::npos) { |
| 174 title_tags.push_back(Tag(Tag::MATCH, | 174 title_tags.push_back(Tag(Tag::MATCH, |
| 175 match_start, | 175 match_start, |
| 176 match_start + match_len)); | 176 match_start + match_len)); |
| 177 match_start = title.find(query, match_start + match_len); | 177 match_start = title.find(query, match_start + match_len); |
| 178 } | 178 } |
| 179 set_title_tags(title_tags); | 179 set_title_tags(title_tags); |
| 180 | 180 |
| 181 base::string16 details = | 181 base::string16 details = |
| 182 base::UTF8ToUTF16(WindowTypeLauncherItem::GetDetails(type_)); | 182 base::UTF8ToUTF16(WindowTypeShelfItem::GetDetails(type_)); |
| 183 set_details(details); | 183 set_details(details); |
| 184 Tags details_tags; | 184 Tags details_tags; |
| 185 details_tags.push_back(Tag(Tag::DIM, 0, details.length())); | 185 details_tags.push_back(Tag(Tag::DIM, 0, details.length())); |
| 186 set_details_tags(details_tags); | 186 set_details_tags(details_tags); |
| 187 } | 187 } |
| 188 | 188 |
| 189 WindowTypeLauncherItem::Type type() const { return type_; } | 189 WindowTypeShelfItem::Type type() const { return type_; } |
| 190 | 190 |
| 191 private: | 191 private: |
| 192 WindowTypeLauncherItem::Type type_; | 192 WindowTypeShelfItem::Type type_; |
| 193 | 193 |
| 194 DISALLOW_COPY_AND_ASSIGN(ExampleSearchResult); | 194 DISALLOW_COPY_AND_ASSIGN(ExampleSearchResult); |
| 195 }; | 195 }; |
| 196 | 196 |
| 197 class ExampleAppListViewDelegate : public app_list::AppListViewDelegate { | 197 class ExampleAppListViewDelegate : public app_list::AppListViewDelegate { |
| 198 public: | 198 public: |
| 199 ExampleAppListViewDelegate() | 199 ExampleAppListViewDelegate() |
| 200 : model_(new app_list::AppListModel) { | 200 : model_(new app_list::AppListModel) { |
| 201 PopulateApps(); | 201 PopulateApps(); |
| 202 DecorateSearchBox(model_->search_box()); | 202 DecorateSearchBox(model_->search_box()); |
| 203 } | 203 } |
| 204 | 204 |
| 205 private: | 205 private: |
| 206 void PopulateApps() { | 206 void PopulateApps() { |
| 207 for (int i = 0; | 207 for (int i = 0; i < static_cast<int>(WindowTypeShelfItem::LAST_TYPE); ++i) { |
| 208 i < static_cast<int>(WindowTypeLauncherItem::LAST_TYPE); | 208 WindowTypeShelfItem::Type type = |
| 209 ++i) { | 209 static_cast<WindowTypeShelfItem::Type>(i); |
| 210 WindowTypeLauncherItem::Type type = | |
| 211 static_cast<WindowTypeLauncherItem::Type>(i); | |
| 212 std::string id = base::StringPrintf("%d", i); | 210 std::string id = base::StringPrintf("%d", i); |
| 213 model_->AddItem(new WindowTypeLauncherItem(id, type)); | 211 model_->AddItem(new WindowTypeShelfItem(id, type)); |
| 214 } | 212 } |
| 215 } | 213 } |
| 216 | 214 |
| 217 gfx::ImageSkia CreateSearchBoxIcon() { | 215 gfx::ImageSkia CreateSearchBoxIcon() { |
| 218 const base::string16 icon_text = base::ASCIIToUTF16("ash"); | 216 const base::string16 icon_text = base::ASCIIToUTF16("ash"); |
| 219 const gfx::Size icon_size(32, 32); | 217 const gfx::Size icon_size(32, 32); |
| 220 | 218 |
| 221 gfx::Canvas canvas(icon_size, 1.0f, false /* is_opaque */); | 219 gfx::Canvas canvas(icon_size, 1.0f, false /* is_opaque */); |
| 222 canvas.DrawStringRectWithFlags( | 220 canvas.DrawStringRectWithFlags( |
| 223 icon_text, | 221 icon_text, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 virtual void GetShortcutPathForApp( | 258 virtual void GetShortcutPathForApp( |
| 261 const std::string& app_id, | 259 const std::string& app_id, |
| 262 const base::Callback<void(const base::FilePath&)>& callback) OVERRIDE { | 260 const base::Callback<void(const base::FilePath&)>& callback) OVERRIDE { |
| 263 callback.Run(base::FilePath()); | 261 callback.Run(base::FilePath()); |
| 264 } | 262 } |
| 265 | 263 |
| 266 virtual void OpenSearchResult(app_list::SearchResult* result, | 264 virtual void OpenSearchResult(app_list::SearchResult* result, |
| 267 int event_flags) OVERRIDE { | 265 int event_flags) OVERRIDE { |
| 268 const ExampleSearchResult* example_result = | 266 const ExampleSearchResult* example_result = |
| 269 static_cast<const ExampleSearchResult*>(result); | 267 static_cast<const ExampleSearchResult*>(result); |
| 270 WindowTypeLauncherItem::ActivateItem(example_result->type(), event_flags); | 268 WindowTypeShelfItem::ActivateItem(example_result->type(), event_flags); |
| 271 } | 269 } |
| 272 | 270 |
| 273 virtual void InvokeSearchResultAction(app_list::SearchResult* result, | 271 virtual void InvokeSearchResultAction(app_list::SearchResult* result, |
| 274 int action_index, | 272 int action_index, |
| 275 int event_flags) OVERRIDE { | 273 int event_flags) OVERRIDE { |
| 276 NOTIMPLEMENTED(); | 274 NOTIMPLEMENTED(); |
| 277 } | 275 } |
| 278 | 276 |
| 279 virtual base::TimeDelta GetAutoLaunchTimeout() OVERRIDE { | 277 virtual base::TimeDelta GetAutoLaunchTimeout() OVERRIDE { |
| 280 return base::TimeDelta(); | 278 return base::TimeDelta(); |
| 281 } | 279 } |
| 282 | 280 |
| 283 virtual void AutoLaunchCanceled() OVERRIDE { | 281 virtual void AutoLaunchCanceled() OVERRIDE { |
| 284 } | 282 } |
| 285 | 283 |
| 286 virtual void StartSearch() OVERRIDE { | 284 virtual void StartSearch() OVERRIDE { |
| 287 base::string16 query; | 285 base::string16 query; |
| 288 TrimWhitespace(model_->search_box()->text(), TRIM_ALL, &query); | 286 TrimWhitespace(model_->search_box()->text(), TRIM_ALL, &query); |
| 289 query = base::i18n::ToLower(query); | 287 query = base::i18n::ToLower(query); |
| 290 | 288 |
| 291 model_->results()->DeleteAll(); | 289 model_->results()->DeleteAll(); |
| 292 if (query.empty()) | 290 if (query.empty()) |
| 293 return; | 291 return; |
| 294 | 292 |
| 295 for (int i = 0; | 293 for (int i = 0; i < static_cast<int>(WindowTypeShelfItem::LAST_TYPE); ++i) { |
| 296 i < static_cast<int>(WindowTypeLauncherItem::LAST_TYPE); | 294 WindowTypeShelfItem::Type type = |
| 297 ++i) { | 295 static_cast<WindowTypeShelfItem::Type>(i); |
| 298 WindowTypeLauncherItem::Type type = | |
| 299 static_cast<WindowTypeLauncherItem::Type>(i); | |
| 300 | 296 |
| 301 base::string16 title = | 297 base::string16 title = |
| 302 base::UTF8ToUTF16(WindowTypeLauncherItem::GetTitle(type)); | 298 base::UTF8ToUTF16(WindowTypeShelfItem::GetTitle(type)); |
| 303 if (base::i18n::StringSearchIgnoringCaseAndAccents( | 299 if (base::i18n::StringSearchIgnoringCaseAndAccents( |
| 304 query, title, NULL, NULL)) { | 300 query, title, NULL, NULL)) { |
| 305 model_->results()->Add(new ExampleSearchResult(type, query)); | 301 model_->results()->Add(new ExampleSearchResult(type, query)); |
| 306 } | 302 } |
| 307 } | 303 } |
| 308 } | 304 } |
| 309 | 305 |
| 310 virtual void StopSearch() OVERRIDE { | 306 virtual void StopSearch() OVERRIDE { |
| 311 // Nothing needs to be done. | 307 // Nothing needs to be done. |
| 312 } | 308 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 }; | 362 }; |
| 367 | 363 |
| 368 } // namespace | 364 } // namespace |
| 369 | 365 |
| 370 app_list::AppListViewDelegate* CreateAppListViewDelegate() { | 366 app_list::AppListViewDelegate* CreateAppListViewDelegate() { |
| 371 return new ExampleAppListViewDelegate; | 367 return new ExampleAppListViewDelegate; |
| 372 } | 368 } |
| 373 | 369 |
| 374 } // namespace shell | 370 } // namespace shell |
| 375 } // namespace ash | 371 } // namespace ash |
| OLD | NEW |