Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.cc

Issue 411543009: Use chrome app favicons in the ChromeOS shelf app window list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" 5 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h"
6 6
7 #include "apps/app_window.h" 7 #include "apps/app_window.h"
8 #include "apps/ui/native_app_window.h" 8 #include "apps/ui/native_app_window.h"
9 #include "ash/shelf/shelf_model.h" 9 #include "ash/shelf/shelf_model.h"
10 #include "ash/wm/window_state.h" 10 #include "ash/wm/window_state.h"
11 #include "ash/wm/window_util.h" 11 #include "ash/wm/window_util.h"
12 #include "chrome/browser/extensions/webstore_install_with_prompt.h" 12 #include "chrome/browser/extensions/webstore_install_with_prompt.h"
13 #include "chrome/browser/favicon/favicon_tab_helper.h"
13 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h"
14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h" 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h"
15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
16 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" 17 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h"
17 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" 18 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
18 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" 19 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
19 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
20 #include "skia/ext/image_operations.h" 21 #include "skia/ext/image_operations.h"
21 #include "ui/aura/client/aura_constants.h" 22 #include "ui/aura/client/aura_constants.h"
22 #include "ui/aura/window.h" 23 #include "ui/aura/window.h"
23 #include "ui/events/event.h" 24 #include "ui/events/event.h"
24 #include "ui/gfx/image/image_skia.h" 25 #include "ui/gfx/image/image_skia.h"
25 #include "ui/wm/core/window_animations.h" 26 #include "ui/wm/core/window_animations.h"
26 27
27 using apps::AppWindow; 28 using apps::AppWindow;
28 29
29 namespace { 30 namespace {
30 31
31 // Size of the icon in the shelf launcher in display-independent pixels. 32 // Size of the icon in the shelf launcher in display-independent pixels.
32 const int kAppListIconSize = 24; 33 const int kAppListIconSize = 24;
33 34
34 // This will return a slightly smaller icon than the app icon to be used in 35 // This will return a slightly smaller icon than the app icon to be used in
35 // the application list menu. 36 // the application list menu.
36 scoped_ptr<gfx::Image> GetAppListIcon(AppWindow* app_window) { 37 gfx::Image GetAppListIcon(AppWindow* app_window) {
37 // TODO(skuhne): We instead might want to use LoadImages in 38 // TODO(skuhne): We instead might want to use LoadImages in
38 // AppWindow::UpdateExtensionAppIcon() to let the extension give us 39 // AppWindow::UpdateExtensionAppIcon() to let the extension give us
39 // pre-defined icons in the launcher and the launcher list sizes. Since there 40 // pre-defined icons in the launcher and the launcher list sizes. Since there
40 // is no mock yet, doing this now seems a bit premature and we scale for the 41 // is no mock yet, doing this now seems a bit premature and we scale for the
41 // time being. 42 // time being.
42 if (app_window->app_icon().IsEmpty()) 43 if (app_window->app_icon().IsEmpty())
43 return make_scoped_ptr(new gfx::Image()); 44 return gfx::Image();
44 45
45 SkBitmap bmp = 46 SkBitmap bmp =
46 skia::ImageOperations::Resize(*app_window->app_icon().ToSkBitmap(), 47 skia::ImageOperations::Resize(*app_window->app_icon().ToSkBitmap(),
47 skia::ImageOperations::RESIZE_BEST, 48 skia::ImageOperations::RESIZE_BEST,
48 kAppListIconSize, 49 kAppListIconSize,
49 kAppListIconSize); 50 kAppListIconSize);
50 return make_scoped_ptr( 51 return gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap(bmp));
51 new gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap(bmp)));
52 } 52 }
53 53
54 // Returns true if the app window is visible on screen, i.e. not hidden or 54 // Returns true if the app window is visible on screen, i.e. not hidden or
55 // minimized. 55 // minimized.
56 bool IsAppWindowVisible(AppWindow* app_window) { 56 bool IsAppWindowVisible(AppWindow* app_window) {
57 return app_window && 57 return app_window &&
58 !app_window->is_hidden() && 58 !app_window->is_hidden() &&
59 !app_window->GetBaseWindow()->IsMinimized(); 59 !app_window->GetBaseWindow()->IsMinimized();
60 } 60 }
61 61
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 194
195 ChromeLauncherAppMenuItems AppWindowLauncherItemController::GetApplicationList( 195 ChromeLauncherAppMenuItems AppWindowLauncherItemController::GetApplicationList(
196 int event_flags) { 196 int event_flags) {
197 ChromeLauncherAppMenuItems items; 197 ChromeLauncherAppMenuItems items;
198 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false)); 198 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false));
199 int index = 0; 199 int index = 0;
200 for (AppWindowList::iterator iter = app_windows_.begin(); 200 for (AppWindowList::iterator iter = app_windows_.begin();
201 iter != app_windows_.end(); 201 iter != app_windows_.end();
202 ++iter) { 202 ++iter) {
203 AppWindow* app_window = *iter; 203 AppWindow* app_window = *iter;
204 scoped_ptr<gfx::Image> image(GetAppListIcon(app_window)); 204
205 // If the app's web contents provides a favicon, use it. Otherwise, use a
206 // scaled down app icon.
207 FaviconTabHelper* favicon_tab_helper =
208 FaviconTabHelper::FromWebContents(app_window->web_contents());
209 gfx::Image result = favicon_tab_helper->GetFavicon();
210 if (result.IsEmpty())
211 result = GetAppListIcon(app_window);
212
205 items.push_back(new ChromeLauncherAppMenuItemV2App( 213 items.push_back(new ChromeLauncherAppMenuItemV2App(
206 app_window->GetTitle(), 214 app_window->GetTitle(),
207 image.get(), // Will be copied 215 &result, // Will be copied
208 app_id(), 216 app_id(),
209 launcher_controller(), 217 launcher_controller(),
210 index, 218 index,
211 index == 0 /* has_leading_separator */)); 219 index == 0 /* has_leading_separator */));
212 ++index; 220 ++index;
213 } 221 }
214 return items.Pass(); 222 return items.Pass();
215 } 223 }
216 224
217 bool AppWindowLauncherItemController::ItemSelected(const ui::Event& event) { 225 bool AppWindowLauncherItemController::ItemSelected(const ui::Event& event) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 } 328 }
321 if (window_to_show->GetBaseWindow()->IsActive()) { 329 if (window_to_show->GetBaseWindow()->IsActive()) {
322 // Coming here, only a single window is active. For keyboard activations 330 // Coming here, only a single window is active. For keyboard activations
323 // the window gets animated. 331 // the window gets animated.
324 AnimateWindow(window_to_show->GetNativeWindow(), 332 AnimateWindow(window_to_show->GetNativeWindow(),
325 wm::WINDOW_ANIMATION_TYPE_BOUNCE); 333 wm::WINDOW_ANIMATION_TYPE_BOUNCE);
326 } else { 334 } else {
327 ShowAndActivateOrMinimize(window_to_show); 335 ShowAndActivateOrMinimize(window_to_show);
328 } 336 }
329 } 337 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698