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

Side by Side Diff: ash/launcher/tabbed_launcher_button.cc

Issue 9649013: Show a different icon in the launcher for incognito windows (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Code review fix Created 8 years, 9 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
OLDNEW
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 "ash/launcher/tabbed_launcher_button.h" 5 #include "ash/launcher/tabbed_launcher_button.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/launcher/launcher_button_host.h" 9 #include "ash/launcher/launcher_button_host.h"
10 #include "ash/launcher/launcher_types.h"
10 #include "grit/ui_resources.h" 11 #include "grit/ui_resources.h"
11 #include "ui/base/accessibility/accessible_view_state.h" 12 #include "ui/base/accessibility/accessible_view_state.h"
12 #include "ui/base/animation/multi_animation.h" 13 #include "ui/base/animation/multi_animation.h"
13 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/gfx/canvas.h" 15 #include "ui/gfx/canvas.h"
15 #include "ui/gfx/image/image.h" 16 #include "ui/gfx/image/image.h"
16 #include "ui/gfx/insets.h" 17 #include "ui/gfx/insets.h"
17 18
18 namespace ash { 19 namespace ash {
19 namespace internal { 20 namespace internal {
(...skipping 18 matching lines...) Expand all
38 const ui::Animation* animation) { 39 const ui::Animation* animation) {
39 if (host_->animation_->current_part_index() == 1) 40 if (host_->animation_->current_part_index() == 1)
40 host_->SchedulePaint(); 41 host_->SchedulePaint();
41 } 42 }
42 43
43 // static 44 // static
44 TabbedLauncherButton::ImageSet* TabbedLauncherButton::bg_image_1_ = NULL; 45 TabbedLauncherButton::ImageSet* TabbedLauncherButton::bg_image_1_ = NULL;
45 TabbedLauncherButton::ImageSet* TabbedLauncherButton::bg_image_2_ = NULL; 46 TabbedLauncherButton::ImageSet* TabbedLauncherButton::bg_image_2_ = NULL;
46 TabbedLauncherButton::ImageSet* TabbedLauncherButton::bg_image_3_ = NULL; 47 TabbedLauncherButton::ImageSet* TabbedLauncherButton::bg_image_3_ = NULL;
47 48
49 TabbedLauncherButton::ImageSet*
50 TabbedLauncherButton::bg_private_image_1_ = NULL;
51 TabbedLauncherButton::ImageSet*
52 TabbedLauncherButton::bg_private_image_2_ = NULL;
53 TabbedLauncherButton::ImageSet*
54 TabbedLauncherButton::bg_private_image_3_ = NULL;
55
48 TabbedLauncherButton::TabbedLauncherButton(views::ButtonListener* listener, 56 TabbedLauncherButton::TabbedLauncherButton(views::ButtonListener* listener,
49 LauncherButtonHost* host) 57 LauncherButtonHost* host)
50 : views::ImageButton(listener), 58 : views::ImageButton(listener),
51 host_(host), 59 host_(host),
52 ALLOW_THIS_IN_INITIALIZER_LIST(animation_delegate_(this)), 60 ALLOW_THIS_IN_INITIALIZER_LIST(animation_delegate_(this)),
53 show_image_(true), 61 show_image_(true),
54 ALLOW_THIS_IN_INITIALIZER_LIST(hover_controller_(this)) { 62 ALLOW_THIS_IN_INITIALIZER_LIST(hover_controller_(this)) {
55 if (!bg_image_1_) { 63 if (!bg_image_1_) {
56 bg_image_1_ = CreateImageSet(IDR_AURA_LAUNCHER_TABBED_BROWSER_1, 64 bg_image_1_ = CreateImageSet(IDR_AURA_LAUNCHER_TABBED_BROWSER_1,
57 IDR_AURA_LAUNCHER_TABBED_BROWSER_1_PUSHED, 65 IDR_AURA_LAUNCHER_TABBED_BROWSER_1_PUSHED,
58 IDR_AURA_LAUNCHER_TABBED_BROWSER_1_HOT); 66 IDR_AURA_LAUNCHER_TABBED_BROWSER_1_HOT);
59 bg_image_2_ = CreateImageSet(IDR_AURA_LAUNCHER_TABBED_BROWSER_2, 67 bg_image_2_ = CreateImageSet(IDR_AURA_LAUNCHER_TABBED_BROWSER_2,
60 IDR_AURA_LAUNCHER_TABBED_BROWSER_2_PUSHED, 68 IDR_AURA_LAUNCHER_TABBED_BROWSER_2_PUSHED,
61 IDR_AURA_LAUNCHER_TABBED_BROWSER_2_HOT); 69 IDR_AURA_LAUNCHER_TABBED_BROWSER_2_HOT);
62 bg_image_3_ = CreateImageSet(IDR_AURA_LAUNCHER_TABBED_BROWSER_3, 70 bg_image_3_ = CreateImageSet(IDR_AURA_LAUNCHER_TABBED_BROWSER_3,
63 IDR_AURA_LAUNCHER_TABBED_BROWSER_3_PUSHED, 71 IDR_AURA_LAUNCHER_TABBED_BROWSER_3_PUSHED,
64 IDR_AURA_LAUNCHER_TABBED_BROWSER_3_HOT); 72 IDR_AURA_LAUNCHER_TABBED_BROWSER_3_HOT);
73
74 bg_private_image_1_ =
75 CreateImageSet(IDR_AURA_LAUNCHER_TABBED_PRIVATE_BROWSER_1,
76 IDR_AURA_LAUNCHER_TABBED_PRIVATE_BROWSER_1_PUSHED,
77 IDR_AURA_LAUNCHER_TABBED_PRIVATE_BROWSER_1_HOT);
78 bg_private_image_2_ =
79 CreateImageSet(IDR_AURA_LAUNCHER_TABBED_PRIVATE_BROWSER_2,
80 IDR_AURA_LAUNCHER_TABBED_PRIVATE_BROWSER_2_PUSHED,
81 IDR_AURA_LAUNCHER_TABBED_PRIVATE_BROWSER_2_HOT);
82 bg_private_image_3_ =
83 CreateImageSet(IDR_AURA_LAUNCHER_TABBED_PRIVATE_BROWSER_3,
84 IDR_AURA_LAUNCHER_TABBED_PRIVATE_BROWSER_3_PUSHED,
85 IDR_AURA_LAUNCHER_TABBED_PRIVATE_BROWSER_3_HOT);
65 } 86 }
66 SetImageAlignment(views::ImageButton::ALIGN_CENTER, 87 SetImageAlignment(views::ImageButton::ALIGN_CENTER,
67 views::ImageButton::ALIGN_MIDDLE); 88 views::ImageButton::ALIGN_MIDDLE);
68 set_accessibility_focusable(true); 89 set_accessibility_focusable(true);
69 } 90 }
70 91
71 TabbedLauncherButton::~TabbedLauncherButton() { 92 TabbedLauncherButton::~TabbedLauncherButton() {
72 } 93 }
73 94
74 void TabbedLauncherButton::PrepareForImageChange() { 95 void TabbedLauncherButton::PrepareForImageChange() {
75 if (!show_image_ || (animation_.get() && animation_->is_animating())) 96 if (!show_image_ || (animation_.get() && animation_->is_animating()))
76 return; 97 return;
77 98
78 // Pause for 500ms, then ease out for 200ms. 99 // Pause for 500ms, then ease out for 200ms.
79 ui::MultiAnimation::Parts animation_parts; 100 ui::MultiAnimation::Parts animation_parts;
80 animation_parts.push_back(ui::MultiAnimation::Part(500, ui::Tween::ZERO)); 101 animation_parts.push_back(ui::MultiAnimation::Part(500, ui::Tween::ZERO));
81 animation_parts.push_back(ui::MultiAnimation::Part(200, ui::Tween::EASE_OUT)); 102 animation_parts.push_back(ui::MultiAnimation::Part(200, ui::Tween::EASE_OUT));
82 animation_.reset(new ui::MultiAnimation(animation_parts)); 103 animation_.reset(new ui::MultiAnimation(animation_parts));
83 animation_->set_continuous(false); 104 animation_->set_continuous(false);
84 animation_->set_delegate(&animation_delegate_); 105 animation_->set_delegate(&animation_delegate_);
85 animation_->Start(); 106 animation_->Start();
86 } 107 }
87 108
88 void TabbedLauncherButton::SetTabImage(const SkBitmap& image, int count) { 109 void TabbedLauncherButton::SetTabImage(const LauncherItem& item) {
89 animation_.reset(); 110 animation_.reset();
90 show_image_ = true; 111 show_image_ = true;
91 image_ = image; 112 image_ = item.image;
92 ImageSet* set; 113 ImageSet* set;
93 if (count <= 1) 114 if (item.is_incognito) {
94 set = bg_image_1_; 115 if (item.num_tabs <= 1)
95 else if (count == 2) 116 set = bg_private_image_1_;
96 set = bg_image_2_; 117 else if (item.num_tabs == 2)
97 else 118 set = bg_private_image_2_;
98 set = bg_image_3_; 119 else
120 set = bg_private_image_3_;
121 } else {
122 if (item.num_tabs <= 1)
123 set = bg_image_1_;
124 else if (item.num_tabs == 2)
125 set = bg_image_2_;
126 else
127 set = bg_image_3_;
128 }
99 SetImage(BS_NORMAL, set->normal_image); 129 SetImage(BS_NORMAL, set->normal_image);
100 SetImage(BS_HOT, set->hot_image); 130 SetImage(BS_HOT, set->hot_image);
101 SetImage(BS_PUSHED, set->pushed_image); 131 SetImage(BS_PUSHED, set->pushed_image);
102 SchedulePaint(); 132 SchedulePaint();
103 } 133 }
104 134
105 void TabbedLauncherButton::OnPaint(gfx::Canvas* canvas) { 135 void TabbedLauncherButton::OnPaint(gfx::Canvas* canvas) {
106 ImageButton::OnPaint(canvas); 136 ImageButton::OnPaint(canvas);
107 137
108 hover_controller_.Draw(canvas, *bg_image_1_->normal_image); 138 hover_controller_.Draw(canvas, *bg_image_1_->normal_image);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 ImageSet* set = new ImageSet; 206 ImageSet* set = new ImageSet;
177 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 207 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
178 set->normal_image = new SkBitmap(*rb.GetImageNamed(normal_id).ToSkBitmap()); 208 set->normal_image = new SkBitmap(*rb.GetImageNamed(normal_id).ToSkBitmap());
179 set->pushed_image = new SkBitmap(*rb.GetImageNamed(pushed_id).ToSkBitmap()); 209 set->pushed_image = new SkBitmap(*rb.GetImageNamed(pushed_id).ToSkBitmap());
180 set->hot_image = new SkBitmap(*rb.GetImageNamed(hot_id).ToSkBitmap()); 210 set->hot_image = new SkBitmap(*rb.GetImageNamed(hot_id).ToSkBitmap());
181 return set; 211 return set;
182 } 212 }
183 213
184 } // namespace internal 214 } // namespace internal
185 } // namespace ash 215 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698