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

Side by Side Diff: ui/views/controls/button/label_button_border.cc

Issue 14631022: Add support for blue buttons. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More feedback Created 7 years, 7 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
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 "ui/views/controls/button/label_button_border.h" 5 #include "ui/views/controls/button/label_button_border.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "grit/ui_resources.h" 8 #include "grit/ui_resources.h"
9 #include "ui/base/animation/animation.h" 9 #include "ui/base/animation/animation.h"
10 #include "ui/gfx/canvas.h" 10 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/rect.h" 11 #include "ui/gfx/rect.h"
12 #include "ui/native_theme/native_theme.h" 12 #include "ui/native_theme/native_theme.h"
13 #include "ui/views/controls/button/label_button.h" 13 #include "ui/views/controls/button/label_button.h"
14 #include "ui/views/native_theme_delegate.h" 14 #include "ui/views/native_theme_delegate.h"
15 15
16 namespace views { 16 namespace views {
17 17
18 namespace { 18 namespace {
19 19
20 // The button image IDs and focused images IDs used in lieu of a focus border. 20 // The button image IDs and focused images IDs used in lieu of a focus border.
21 const int kNormalImages[] = IMAGE_GRID(IDR_BUTTON_NORMAL); 21 const int kNormalImages[] = IMAGE_GRID(IDR_BUTTON_NORMAL);
22 const int kHoveredImages[] = IMAGE_GRID(IDR_BUTTON_HOVER); 22 const int kHoveredImages[] = IMAGE_GRID(IDR_BUTTON_HOVER);
23 const int kPressedImages[] = IMAGE_GRID(IDR_BUTTON_PRESSED); 23 const int kPressedImages[] = IMAGE_GRID(IDR_BUTTON_PRESSED);
24 const int kFocusedNormalImages[] = IMAGE_GRID(IDR_BUTTON_FOCUSED_NORMAL); 24 const int kFocusedNormalImages[] = IMAGE_GRID(IDR_BUTTON_FOCUSED_NORMAL);
25 const int kFocusedHoveredImages[] = IMAGE_GRID(IDR_BUTTON_FOCUSED_HOVER); 25 const int kFocusedHoveredImages[] = IMAGE_GRID(IDR_BUTTON_FOCUSED_HOVER);
26 const int kFocusedPressedImages[] = IMAGE_GRID(IDR_BUTTON_FOCUSED_PRESSED); 26 const int kFocusedPressedImages[] = IMAGE_GRID(IDR_BUTTON_FOCUSED_PRESSED);
27 27
28 const int kBlueNormalImages[] = IMAGE_GRID(IDR_BLUE_BUTTON_NORMAL);
29 const int kBlueHoveredImages[] = IMAGE_GRID(IDR_BLUE_BUTTON_HOVER);
30 const int kBluePressedImages[] = IMAGE_GRID(IDR_BLUE_BUTTON_PRESSED);
31 const int kBlueFocusedNormalImages[] = IMAGE_GRID(
32 IDR_BLUE_BUTTON_FOCUSED_NORMAL);
33 const int kBlueFocusedHoveredImages[] = IMAGE_GRID(
34 IDR_BLUE_BUTTON_FOCUSED_HOVER);
35 const int kBlueFocusedPressedImages[] = IMAGE_GRID(
36 IDR_BLUE_BUTTON_FOCUSED_PRESSED);
37
28 // The text-button hot and pushed image IDs; normal is unadorned by default. 38 // The text-button hot and pushed image IDs; normal is unadorned by default.
29 const int kTextHoveredImages[] = IMAGE_GRID(IDR_TEXTBUTTON_HOVER); 39 const int kTextHoveredImages[] = IMAGE_GRID(IDR_TEXTBUTTON_HOVER);
30 const int kTextPressedImages[] = IMAGE_GRID(IDR_TEXTBUTTON_PRESSED); 40 const int kTextPressedImages[] = IMAGE_GRID(IDR_TEXTBUTTON_PRESSED);
31 41
32 Button::ButtonState GetButtonState(ui::NativeTheme::State state) { 42 Button::ButtonState GetButtonState(ui::NativeTheme::State state) {
33 switch(state) { 43 switch(state) {
34 case ui::NativeTheme::kDisabled: return Button::STATE_DISABLED; 44 case ui::NativeTheme::kDisabled: return Button::STATE_DISABLED;
35 case ui::NativeTheme::kHovered: return Button::STATE_HOVERED; 45 case ui::NativeTheme::kHovered: return Button::STATE_HOVERED;
36 case ui::NativeTheme::kNormal: return Button::STATE_NORMAL; 46 case ui::NativeTheme::kNormal: return Button::STATE_NORMAL;
37 case ui::NativeTheme::kPressed: return Button::STATE_PRESSED; 47 case ui::NativeTheme::kPressed: return Button::STATE_PRESSED;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 Painter::CreateImageGridPainter(kFocusedHoveredImages)); 90 Painter::CreateImageGridPainter(kFocusedHoveredImages));
81 SetPainter(true, Button::STATE_PRESSED, 91 SetPainter(true, Button::STATE_PRESSED,
82 Painter::CreateImageGridPainter(kFocusedPressedImages)); 92 Painter::CreateImageGridPainter(kFocusedPressedImages));
83 SetPainter(true, Button::STATE_DISABLED, 93 SetPainter(true, Button::STATE_DISABLED,
84 Painter::CreateImageGridPainter(kNormalImages)); 94 Painter::CreateImageGridPainter(kNormalImages));
85 } else if (style == Button::STYLE_TEXTBUTTON) { 95 } else if (style == Button::STYLE_TEXTBUTTON) {
86 SetPainter(false, Button::STATE_HOVERED, 96 SetPainter(false, Button::STATE_HOVERED,
87 Painter::CreateImageGridPainter(kTextHoveredImages)); 97 Painter::CreateImageGridPainter(kTextHoveredImages));
88 SetPainter(false, Button::STATE_PRESSED, 98 SetPainter(false, Button::STATE_PRESSED,
89 Painter::CreateImageGridPainter(kTextPressedImages)); 99 Painter::CreateImageGridPainter(kTextPressedImages));
100 } else if (style == Button::STYLE_BLUE_BUTTON) {
101 SetPainter(false, Button::STATE_NORMAL,
102 Painter::CreateImageGridPainter(kBlueNormalImages));
103 SetPainter(false, Button::STATE_HOVERED,
104 Painter::CreateImageGridPainter(kBlueHoveredImages));
105 SetPainter(false, Button::STATE_PRESSED,
106 Painter::CreateImageGridPainter(kBluePressedImages));
107 SetPainter(false, Button::STATE_DISABLED,
108 Painter::CreateImageGridPainter(kBlueNormalImages));
109 SetPainter(true, Button::STATE_NORMAL,
110 Painter::CreateImageGridPainter(kBlueFocusedNormalImages));
111 SetPainter(true, Button::STATE_HOVERED,
112 Painter::CreateImageGridPainter(kBlueFocusedHoveredImages));
113 SetPainter(true, Button::STATE_PRESSED,
114 Painter::CreateImageGridPainter(kBlueFocusedPressedImages));
115 SetPainter(true, Button::STATE_DISABLED,
116 Painter::CreateImageGridPainter(kBlueNormalImages));
90 } 117 }
91 } 118 }
92 119
93 LabelButtonBorder::~LabelButtonBorder() {} 120 LabelButtonBorder::~LabelButtonBorder() {}
94 121
95 void LabelButtonBorder::Paint(const View& view, gfx::Canvas* canvas) { 122 void LabelButtonBorder::Paint(const View& view, gfx::Canvas* canvas) {
96 DCHECK(!strcmp(view.GetClassName(), LabelButton::kViewClassName)); 123 DCHECK(!strcmp(view.GetClassName(), LabelButton::kViewClassName));
97 const NativeThemeDelegate* native_theme_delegate = 124 const NativeThemeDelegate* native_theme_delegate =
98 static_cast<const LabelButton*>(&view); 125 static_cast<const LabelButton*>(&view);
99 ui::NativeTheme::Part part = native_theme_delegate->GetThemePart(); 126 ui::NativeTheme::Part part = native_theme_delegate->GetThemePart();
100 gfx::Rect rect(native_theme_delegate->GetThemePaintRect()); 127 gfx::Rect rect(native_theme_delegate->GetThemePaintRect());
101 ui::NativeTheme::ExtraParams extra; 128 ui::NativeTheme::ExtraParams extra;
102 const ui::NativeTheme* theme = view.GetNativeTheme(); 129 const ui::NativeTheme* theme = view.GetNativeTheme();
103 const ui::Animation* animation = native_theme_delegate->GetThemeAnimation(); 130 const ui::Animation* animation = native_theme_delegate->GetThemeAnimation();
104 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra); 131 ui::NativeTheme::State state = native_theme_delegate->GetThemeState(&extra);
105 132
106 if (animation && animation->is_animating()) { 133 // TODO(msw): re-enable animation is for blue buttons. It's disabled now due
msw 2013/05/18 20:07:24 nit: capitalization and s/animation is/animations/
benwells 2013/05/24 07:44:22 Done.
134 // to crbug.com/239121.
135 if (animation && animation->is_animating() &&
136 style() != Button::STYLE_BLUE_BUTTON) {
107 // Composite the background and foreground painters during state animations. 137 // Composite the background and foreground painters during state animations.
108 int alpha = animation->CurrentValueBetween(0, 0xff); 138 int alpha = animation->CurrentValueBetween(0, 0xff);
109 state = native_theme_delegate->GetBackgroundThemeState(&extra); 139 state = native_theme_delegate->GetBackgroundThemeState(&extra);
110 canvas->SaveLayerAlpha(static_cast<uint8>(0xff - alpha)); 140 canvas->SaveLayerAlpha(static_cast<uint8>(0xff - alpha));
111 PaintHelper(this, canvas, theme, part, state, rect, extra); 141 PaintHelper(this, canvas, theme, part, state, rect, extra);
112 canvas->Restore(); 142 canvas->Restore();
113 143
114 state = native_theme_delegate->GetForegroundThemeState(&extra); 144 state = native_theme_delegate->GetForegroundThemeState(&extra);
115 canvas->SaveLayerAlpha(static_cast<uint8>(alpha)); 145 canvas->SaveLayerAlpha(static_cast<uint8>(alpha));
116 PaintHelper(this, canvas, theme, part, state, rect, extra); 146 PaintHelper(this, canvas, theme, part, state, rect, extra);
117 canvas->Restore(); 147 canvas->Restore();
118 } else if (state == ui::NativeTheme::kDisabled && 148 } else if (state == ui::NativeTheme::kDisabled &&
119 style() == Button::STYLE_BUTTON) { 149 (style() == Button::STYLE_BUTTON ||
150 style() == Button::STYLE_BLUE_BUTTON)) {
120 canvas->SaveLayerAlpha(static_cast<uint8>(0xff / 2)); 151 canvas->SaveLayerAlpha(static_cast<uint8>(0xff / 2));
121 PaintHelper(this, canvas, theme, part, state, rect, extra); 152 PaintHelper(this, canvas, theme, part, state, rect, extra);
122 canvas->Restore(); 153 canvas->Restore();
123 } else { 154 } else {
124 PaintHelper(this, canvas, theme, part, state, rect, extra); 155 PaintHelper(this, canvas, theme, part, state, rect, extra);
125 } 156 }
126 157
127 // Draw the Views focus border for the native theme style. 158 // Draw the Views focus border for the native theme style.
128 if (style() == Button::STYLE_NATIVE_TEXTBUTTON && 159 if (style() == Button::STYLE_NATIVE_TEXTBUTTON &&
129 view.focus_border() && extra.button.is_focused) 160 view.focus_border() && extra.button.is_focused)
130 view.focus_border()->Paint(view, canvas); 161 view.focus_border()->Paint(view, canvas);
131 } 162 }
132 163
133 gfx::Insets LabelButtonBorder::GetInsets() const { 164 gfx::Insets LabelButtonBorder::GetInsets() const {
134 // Return the style-specific insets between button contents and edges. 165 // Return the style-specific insets between button contents and edges.
135 if (style() == Button::STYLE_BUTTON) 166 if (style() == Button::STYLE_BUTTON || style() == Button::STYLE_BLUE_BUTTON)
136 return gfx::Insets(9, 13, 9, 13); 167 return gfx::Insets(9, 13, 9, 13);
137 if (style() == Button::STYLE_TEXTBUTTON) 168 if (style() == Button::STYLE_TEXTBUTTON)
138 return gfx::Insets(5, 6, 5, 6); 169 return gfx::Insets(5, 6, 5, 6);
139 if (style() == Button::STYLE_NATIVE_TEXTBUTTON) 170 if (style() == Button::STYLE_NATIVE_TEXTBUTTON)
140 return gfx::Insets(5, 12, 5, 12); 171 return gfx::Insets(5, 12, 5, 12);
141 NOTREACHED(); 172 NOTREACHED();
142 return gfx::Insets(); 173 return gfx::Insets();
143 } 174 }
144 175
145 Painter* LabelButtonBorder::GetPainter(bool focused, 176 Painter* LabelButtonBorder::GetPainter(bool focused,
146 Button::ButtonState state) { 177 Button::ButtonState state) {
147 return painters_[focused ? 1 : 0][state].get(); 178 return painters_[focused ? 1 : 0][state].get();
148 } 179 }
149 180
150 void LabelButtonBorder::SetPainter(bool focused, 181 void LabelButtonBorder::SetPainter(bool focused,
151 Button::ButtonState state, 182 Button::ButtonState state,
152 Painter* painter) { 183 Painter* painter) {
153 painters_[focused ? 1 : 0][state].reset(painter); 184 painters_[focused ? 1 : 0][state].reset(painter);
154 } 185 }
155 186
156 } // namespace views 187 } // namespace views
OLDNEW
« ui/views/controls/button/label_button.cc ('K') | « ui/views/controls/button/label_button.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698