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

Side by Side Diff: ui/aura_shell/launcher/tabbed_launcher_button.cc

Issue 8933010: Wires up new launcher images. To get the official images for the (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile Created 9 years 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 | « ui/aura_shell/launcher/tabbed_launcher_button.h ('k') | ui/aura_shell/shell_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/aura_shell/launcher/tabbed_launcher_button.h" 5 #include "ui/aura_shell/launcher/tabbed_launcher_button.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "grit/ui_resources.h" 9 #include "grit/ui_resources.h"
10 #include "ui/aura_shell/launcher/launcher_button_host.h" 10 #include "ui/aura_shell/launcher/launcher_button_host.h"
(...skipping 14 matching lines...) Expand all
25 25
26 // Insets used in painting the background if it's rendered bigger than the size 26 // Insets used in painting the background if it's rendered bigger than the size
27 // of the background image. See ImagePainter::CreateImagePainter for how these 27 // of the background image. See ImagePainter::CreateImagePainter for how these
28 // are interpreted. 28 // are interpreted.
29 const int kBgTopInset = 12; 29 const int kBgTopInset = 12;
30 const int kBgLeftInset = 30; 30 const int kBgLeftInset = 30;
31 const int kBgBottomInset = 12; 31 const int kBgBottomInset = 12;
32 const int kBgRightInset = 8; 32 const int kBgRightInset = 8;
33 33
34 // static 34 // static
35 SkBitmap* TabbedLauncherButton::bg_image_1_ = NULL; 35 TabbedLauncherButton::ImageSet* TabbedLauncherButton::bg_image_1_ = NULL;
36 SkBitmap* TabbedLauncherButton::bg_image_2_ = NULL; 36 TabbedLauncherButton::ImageSet* TabbedLauncherButton::bg_image_2_ = NULL;
37 SkBitmap* TabbedLauncherButton::bg_image_3_ = NULL; 37 TabbedLauncherButton::ImageSet* TabbedLauncherButton::bg_image_3_ = NULL;
38 38
39 TabbedLauncherButton::TabbedLauncherButton(views::ButtonListener* listener, 39 TabbedLauncherButton::TabbedLauncherButton(views::ButtonListener* listener,
40 LauncherButtonHost* host) 40 LauncherButtonHost* host)
41 : views::CustomButton(listener), 41 : views::ImageButton(listener),
42 host_(host) { 42 host_(host) {
43 if (!bg_image_1_) { 43 if (!bg_image_1_) {
44 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 44 bg_image_1_ = CreateImageSet(IDR_AURA_LAUNCHER_TABBED_BROWSER_1,
45 bg_image_1_ = new SkBitmap( 45 IDR_AURA_LAUNCHER_TABBED_BROWSER_1_PUSHED,
46 *rb.GetImageNamed(IDR_AURA_LAUNCHER_TABBED_BROWSER_1).ToSkBitmap()); 46 IDR_AURA_LAUNCHER_TABBED_BROWSER_1_HOT);
47 bg_image_2_ = new SkBitmap( 47 bg_image_2_ = CreateImageSet(IDR_AURA_LAUNCHER_TABBED_BROWSER_2,
48 *rb.GetImageNamed(IDR_AURA_LAUNCHER_TABBED_BROWSER_2).ToSkBitmap()); 48 IDR_AURA_LAUNCHER_TABBED_BROWSER_2_PUSHED,
49 bg_image_3_ = new SkBitmap( 49 IDR_AURA_LAUNCHER_TABBED_BROWSER_2_HOT);
50 *rb.GetImageNamed(IDR_AURA_LAUNCHER_TABBED_BROWSER_3).ToSkBitmap()); 50 bg_image_3_ = CreateImageSet(IDR_AURA_LAUNCHER_TABBED_BROWSER_3,
51 IDR_AURA_LAUNCHER_TABBED_BROWSER_3_PUSHED,
52 IDR_AURA_LAUNCHER_TABBED_BROWSER_3_HOT);
51 } 53 }
54 SetImageAlignment(views::ImageButton::ALIGN_CENTER,
55 views::ImageButton::ALIGN_MIDDLE);
52 } 56 }
53 57
54 TabbedLauncherButton::~TabbedLauncherButton() { 58 TabbedLauncherButton::~TabbedLauncherButton() {
55 } 59 }
56 60
57 void TabbedLauncherButton::SetImages(const LauncherTabbedImages& images) { 61 void TabbedLauncherButton::SetImages(const LauncherTabbedImages& images) {
58 images_ = images; 62 images_ = images;
59 } 63 ImageSet* set;
60 64 if (images_.size() <= 1)
61 gfx::Size TabbedLauncherButton::GetPreferredSize() { 65 set = bg_image_1_;
62 return gfx::Size(bg_image_1_->width(), bg_image_1_->height()); 66 else if (images_.size() == 2)
67 set = bg_image_2_;
68 else
69 set = bg_image_3_;
70 SetImage(BS_NORMAL, set->normal_image);
71 SetImage(BS_HOT, set->hot_image);
72 SetImage(BS_PUSHED, set->pushed_image);
63 } 73 }
64 74
65 void TabbedLauncherButton::OnPaint(gfx::Canvas* canvas) { 75 void TabbedLauncherButton::OnPaint(gfx::Canvas* canvas) {
66 SkBitmap* bg_image = NULL; 76 ImageButton::OnPaint(canvas);
67 if (images_.size() <= 1)
68 bg_image = bg_image_1_;
69 else if (images_.size() == 2)
70 bg_image = bg_image_2_;
71 else
72 bg_image = bg_image_3_;
73 canvas->DrawBitmapInt(*bg_image, 0, 0);
74 77
75 if (images_.empty()) 78 if (images_.empty())
76 return; 79 return;
77 80
78 // Only show the first icon. 81 // Only show the first icon.
79 // TODO(sky): if we settle on just 1 icon, then we should simplify surrounding 82 // TODO(sky): if we settle on just 1 icon, then we should simplify surrounding
80 // code (don't use a vector of images). 83 // code (don't use a vector of images).
81 int x = (width() - images_[0].image.width()) / 2; 84 int x = (width() - images_[0].image.width()) / 2;
82 int y = (height() - images_[0].image.height()) / 2; 85 int y = (height() - images_[0].image.height()) / 2 + 1;
83 canvas->DrawBitmapInt(images_[0].image, x, y); 86 canvas->DrawBitmapInt(images_[0].image, x, y);
84 } 87 }
85 88
86 bool TabbedLauncherButton::OnMousePressed(const views::MouseEvent& event) { 89 bool TabbedLauncherButton::OnMousePressed(const views::MouseEvent& event) {
87 CustomButton::OnMousePressed(event); 90 ImageButton::OnMousePressed(event);
88 host_->MousePressedOnButton(this, event); 91 host_->MousePressedOnButton(this, event);
89 return true; 92 return true;
90 } 93 }
91 94
92 void TabbedLauncherButton::OnMouseReleased(const views::MouseEvent& event) { 95 void TabbedLauncherButton::OnMouseReleased(const views::MouseEvent& event) {
93 host_->MouseReleasedOnButton(this, false); 96 host_->MouseReleasedOnButton(this, false);
94 CustomButton::OnMouseReleased(event); 97 ImageButton::OnMouseReleased(event);
95 } 98 }
96 99
97 void TabbedLauncherButton::OnMouseCaptureLost() { 100 void TabbedLauncherButton::OnMouseCaptureLost() {
98 host_->MouseReleasedOnButton(this, true); 101 host_->MouseReleasedOnButton(this, true);
99 CustomButton::OnMouseCaptureLost(); 102 ImageButton::OnMouseCaptureLost();
100 } 103 }
101 104
102 bool TabbedLauncherButton::OnMouseDragged(const views::MouseEvent& event) { 105 bool TabbedLauncherButton::OnMouseDragged(const views::MouseEvent& event) {
103 CustomButton::OnMouseDragged(event); 106 ImageButton::OnMouseDragged(event);
104 host_->MouseDraggedOnButton(this, event); 107 host_->MouseDraggedOnButton(this, event);
105 return true; 108 return true;
106 } 109 }
107 110
111 // static
112 TabbedLauncherButton::ImageSet* TabbedLauncherButton::CreateImageSet(
113 int normal_id,
114 int pushed_id,
115 int hot_id) {
116 ImageSet* set = new ImageSet;
117 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
118 set->normal_image = new SkBitmap(*rb.GetImageNamed(normal_id).ToSkBitmap());
119 set->pushed_image = new SkBitmap(*rb.GetImageNamed(pushed_id).ToSkBitmap());
120 set->hot_image = new SkBitmap(*rb.GetImageNamed(hot_id).ToSkBitmap());
121 return set;
122 }
123
108 } // namespace internal 124 } // namespace internal
109 } // namespace aura_shell 125 } // namespace aura_shell
OLDNEW
« no previous file with comments | « ui/aura_shell/launcher/tabbed_launcher_button.h ('k') | ui/aura_shell/shell_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698