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

Side by Side Diff: chrome/browser/ui/extensions/extension_action_view_controller.cc

Issue 1454753002: Resize extension action icons to 16x16 in material design (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
« 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/extensions/extension_action_view_controller.h" 5 #include "chrome/browser/ui/extensions/extension_action_view_controller.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/extensions/api/commands/command_service.h" 9 #include "chrome/browser/extensions/api/commands/command_service.h"
10 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" 10 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
11 #include "chrome/browser/extensions/extension_action.h" 11 #include "chrome/browser/extensions/extension_action.h"
12 #include "chrome/browser/extensions/extension_view.h" 12 #include "chrome/browser/extensions/extension_view.h"
13 #include "chrome/browser/extensions/extension_view_host.h" 13 #include "chrome/browser/extensions/extension_view_host.h"
14 #include "chrome/browser/extensions/extension_view_host_factory.h" 14 #include "chrome/browser/extensions/extension_view_host_factory.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/sessions/session_tab_helper.h" 16 #include "chrome/browser/sessions/session_tab_helper.h"
17 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/extensions/accelerator_priority.h" 18 #include "chrome/browser/ui/extensions/accelerator_priority.h"
19 #include "chrome/browser/ui/extensions/extension_action_platform_delegate.h" 19 #include "chrome/browser/ui/extensions/extension_action_platform_delegate.h"
20 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" 20 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h"
21 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" 21 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
22 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" 22 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
23 #include "chrome/common/extensions/api/extension_action/action_info.h" 23 #include "chrome/common/extensions/api/extension_action/action_info.h"
24 #include "chrome/common/icon_with_badge_image_source.h" 24 #include "chrome/common/icon_with_badge_image_source.h"
25 #include "extensions/browser/extension_host.h" 25 #include "extensions/browser/extension_host.h"
26 #include "extensions/browser/extension_registry.h" 26 #include "extensions/browser/extension_registry.h"
27 #include "extensions/common/extension.h" 27 #include "extensions/common/extension.h"
28 #include "extensions/common/feature_switch.h" 28 #include "extensions/common/feature_switch.h"
29 #include "extensions/common/manifest_constants.h" 29 #include "extensions/common/manifest_constants.h"
30 #include "ui/base/resource/material_design/material_design_controller.h"
30 #include "ui/gfx/image/image_skia.h" 31 #include "ui/gfx/image/image_skia.h"
31 #include "ui/gfx/image/image_skia_operations.h" 32 #include "ui/gfx/image/image_skia_operations.h"
32 33
33 using extensions::ActionInfo; 34 using extensions::ActionInfo;
34 using extensions::CommandService; 35 using extensions::CommandService;
35 36
36 ExtensionActionViewController::ExtensionActionViewController( 37 ExtensionActionViewController::ExtensionActionViewController(
37 const extensions::Extension* extension, 38 const extensions::Extension* extension,
38 Browser* browser, 39 Browser* browser,
39 ExtensionAction* extension_action, 40 ExtensionAction* extension_action,
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 view_delegate_->OnPopupClosed(); 358 view_delegate_->OnPopupClosed();
358 } 359 }
359 360
360 scoped_ptr<IconWithBadgeImageSource> 361 scoped_ptr<IconWithBadgeImageSource>
361 ExtensionActionViewController::GetIconImageSource( 362 ExtensionActionViewController::GetIconImageSource(
362 content::WebContents* web_contents, 363 content::WebContents* web_contents,
363 const gfx::Size& size) { 364 const gfx::Size& size) {
364 int tab_id = SessionTabHelper::IdForTab(web_contents); 365 int tab_id = SessionTabHelper::IdForTab(web_contents);
365 scoped_ptr<IconWithBadgeImageSource> image_source( 366 scoped_ptr<IconWithBadgeImageSource> image_source(
366 new IconWithBadgeImageSource(size)); 367 new IconWithBadgeImageSource(size));
367 image_source->SetIcon(icon_factory_.GetIcon(tab_id)); 368
369 gfx::Image icon(icon_factory_.GetIcon(tab_id));
370 if (ui::MaterialDesignController::IsModeMaterial()) {
371 // TODO(tdanderson): Use a 16x16 icon if it exists instead of resizing.
372 icon = gfx::Image(gfx::ImageSkiaOperations::CreateResizedImage(
373 *icon.ToImageSkia(),
374 skia::ImageOperations::RESIZE_BEST,
375 gfx::Size(extension_misc::EXTENSION_ICON_BITTY,
376 extension_misc::EXTENSION_ICON_BITTY)));
377 }
378 image_source->SetIcon(icon);
379
368 scoped_ptr<IconWithBadgeImageSource::Badge> badge; 380 scoped_ptr<IconWithBadgeImageSource::Badge> badge;
369 std::string badge_text = extension_action_->GetBadgeText(tab_id); 381 std::string badge_text = extension_action_->GetBadgeText(tab_id);
370 if (!badge_text.empty()) { 382 if (!badge_text.empty()) {
371 badge.reset(new IconWithBadgeImageSource::Badge( 383 badge.reset(new IconWithBadgeImageSource::Badge(
372 badge_text, 384 badge_text,
373 extension_action_->GetBadgeTextColor(tab_id), 385 extension_action_->GetBadgeTextColor(tab_id),
374 extension_action_->GetBadgeBackgroundColor(tab_id))); 386 extension_action_->GetBadgeBackgroundColor(tab_id)));
375 } 387 }
376 image_source->SetBadge(badge.Pass()); 388 image_source->SetBadge(badge.Pass());
377 389
378 // Greyscaling disabled actions and having a special wants-to-run decoration 390 // Greyscaling disabled actions and having a special wants-to-run decoration
379 // are gated on the toolbar redesign. 391 // are gated on the toolbar redesign.
380 if (extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) { 392 if (extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) {
381 // If the extension doesn't want to run on the active web contents, we 393 // If the extension doesn't want to run on the active web contents, we
382 // grayscale it to indicate that. 394 // grayscale it to indicate that.
383 image_source->set_grayscale(!IsEnabled(web_contents)); 395 image_source->set_grayscale(!IsEnabled(web_contents));
384 // If the action *does* want to run on the active web contents and is also 396 // If the action *does* want to run on the active web contents and is also
385 // overflowed, we add a decoration so that the user can see which overflowed 397 // overflowed, we add a decoration so that the user can see which overflowed
386 // action wants to run (since they wouldn't be able to see the change from 398 // action wants to run (since they wouldn't be able to see the change from
387 // grayscale to color). 399 // grayscale to color).
388 bool is_overflow = 400 bool is_overflow =
389 toolbar_actions_bar_ && toolbar_actions_bar_->in_overflow_mode(); 401 toolbar_actions_bar_ && toolbar_actions_bar_->in_overflow_mode();
390 image_source->set_paint_decoration(WantsToRun(web_contents) && is_overflow); 402 image_source->set_paint_decoration(WantsToRun(web_contents) && is_overflow);
391 } 403 }
392 404
393 return image_source.Pass(); 405 return image_source.Pass();
394 } 406 }
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