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

Side by Side Diff: ui/views/examples/native_theme_button_example.cc

Issue 10387121: Revert 136996 - ui: Move NativeTheme files into ui/base/native_theme/ directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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/examples/native_theme_button_example.h" 5 #include "ui/views/examples/native_theme_button_example.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 set_background(Background::CreateBackgroundPainter( 56 set_background(Background::CreateBackgroundPainter(
57 false, painter_.get())); 57 false, painter_.get()));
58 } 58 }
59 59
60 ExampleNativeThemeButton::~ExampleNativeThemeButton() { 60 ExampleNativeThemeButton::~ExampleNativeThemeButton() {
61 } 61 }
62 62
63 std::string ExampleNativeThemeButton::MessWithState() { 63 std::string ExampleNativeThemeButton::MessWithState() {
64 const char* message = NULL; 64 const char* message = NULL;
65 switch (GetThemePart()) { 65 switch (GetThemePart()) {
66 case ui::NativeTheme::kPushButton: 66 case gfx::NativeTheme::kPushButton:
67 message = "Pressed! count:%d"; 67 message = "Pressed! count:%d";
68 break; 68 break;
69 case ui::NativeTheme::kRadio: 69 case gfx::NativeTheme::kRadio:
70 is_checked_ = !is_checked_; 70 is_checked_ = !is_checked_;
71 message = is_checked_ ? "Checked! count:%d" : "Unchecked! count:%d"; 71 message = is_checked_ ? "Checked! count:%d" : "Unchecked! count:%d";
72 break; 72 break;
73 case ui::NativeTheme::kCheckbox: 73 case gfx::NativeTheme::kCheckbox:
74 if (is_indeterminate_) { 74 if (is_indeterminate_) {
75 is_checked_ = false; 75 is_checked_ = false;
76 is_indeterminate_ = false; 76 is_indeterminate_ = false;
77 } else if (!is_checked_) { 77 } else if (!is_checked_) {
78 is_checked_ = true; 78 is_checked_ = true;
79 } else { 79 } else {
80 is_checked_ = false; 80 is_checked_ = false;
81 is_indeterminate_ = true; 81 is_indeterminate_ = true;
82 } 82 }
83 if (is_checked_) 83 if (is_checked_)
84 message = "Checked! count:%d"; 84 message = "Checked! count:%d";
85 else if (is_indeterminate_) 85 else if (is_indeterminate_)
86 message = "Indeterminate! count:%d"; 86 message = "Indeterminate! count:%d";
87 else 87 else
88 message = "Unchecked! count:%d"; 88 message = "Unchecked! count:%d";
89 break; 89 break;
90 default: 90 default:
91 NOTREACHED(); 91 NOTREACHED();
92 } 92 }
93 93
94 return base::StringPrintf(message, ++count_); 94 return base::StringPrintf(message, ++count_);
95 } 95 }
96 96
97 void ExampleNativeThemeButton::OnSelectedIndexChanged(Combobox* combobox) { 97 void ExampleNativeThemeButton::OnSelectedIndexChanged(Combobox* combobox) {
98 SchedulePaint(); 98 SchedulePaint();
99 } 99 }
100 100
101 ui::NativeTheme::Part ExampleNativeThemeButton::GetThemePart() const { 101 gfx::NativeTheme::Part ExampleNativeThemeButton::GetThemePart() const {
102 switch (cb_part_->selected_index()) { 102 switch (cb_part_->selected_index()) {
103 case 0: 103 case 0:
104 return ui::NativeTheme::kPushButton; 104 return gfx::NativeTheme::kPushButton;
105 case 1: 105 case 1:
106 return ui::NativeTheme::kRadio; 106 return gfx::NativeTheme::kRadio;
107 case 2: 107 case 2:
108 return ui::NativeTheme::kCheckbox; 108 return gfx::NativeTheme::kCheckbox;
109 default: 109 default:
110 NOTREACHED(); 110 NOTREACHED();
111 } 111 }
112 return ui::NativeTheme::kPushButton; 112 return gfx::NativeTheme::kPushButton;
113 } 113 }
114 114
115 gfx::Rect ExampleNativeThemeButton::GetThemePaintRect() const { 115 gfx::Rect ExampleNativeThemeButton::GetThemePaintRect() const {
116 ui::NativeTheme::ExtraParams extra; 116 gfx::NativeTheme::ExtraParams extra;
117 ui::NativeTheme::State state = GetThemeState(&extra); 117 gfx::NativeTheme::State state = GetThemeState(&extra);
118 gfx::Size size(ui::NativeTheme::instance()->GetPartSize(GetThemePart(), state, 118 gfx::Size size(gfx::NativeTheme::instance()->GetPartSize(GetThemePart(),
119 extra)); 119 state,
120 extra));
120 gfx::Rect rect(size); 121 gfx::Rect rect(size);
121 rect.set_x(GetMirroredXForRect(rect)); 122 rect.set_x(GetMirroredXForRect(rect));
122 return rect; 123 return rect;
123 } 124 }
124 125
125 ui::NativeTheme::State ExampleNativeThemeButton::GetThemeState( 126 gfx::NativeTheme::State ExampleNativeThemeButton::GetThemeState(
126 ui::NativeTheme::ExtraParams* params) const { 127 gfx::NativeTheme::ExtraParams* params) const {
127 GetExtraParams(params); 128 GetExtraParams(params);
128 129
129 int selected = cb_state_->selected_index(); 130 int selected = cb_state_->selected_index();
130 if (selected > 3) { 131 if (selected > 3) {
131 switch (state()) { 132 switch (state()) {
132 case BS_DISABLED: 133 case BS_DISABLED:
133 return ui::NativeTheme::kDisabled; 134 return gfx::NativeTheme::kDisabled;
134 case BS_NORMAL: 135 case BS_NORMAL:
135 return ui::NativeTheme::kNormal; 136 return gfx::NativeTheme::kNormal;
136 case BS_HOT: 137 case BS_HOT:
137 return ui::NativeTheme::kHovered; 138 return gfx::NativeTheme::kHovered;
138 case BS_PUSHED: 139 case BS_PUSHED:
139 return ui::NativeTheme::kPressed; 140 return gfx::NativeTheme::kPressed;
140 default: 141 default:
141 NOTREACHED(); 142 NOTREACHED();
142 } 143 }
143 } 144 }
144 145
145 switch (selected) { 146 switch (selected) {
146 case 0: 147 case 0:
147 return ui::NativeTheme::kDisabled; 148 return gfx::NativeTheme::kDisabled;
148 case 1: 149 case 1:
149 return ui::NativeTheme::kNormal; 150 return gfx::NativeTheme::kNormal;
150 case 2: 151 case 2:
151 return ui::NativeTheme::kHovered; 152 return gfx::NativeTheme::kHovered;
152 case 3: 153 case 3:
153 return ui::NativeTheme::kPressed; 154 return gfx::NativeTheme::kPressed;
154 default: 155 default:
155 NOTREACHED(); 156 NOTREACHED();
156 } 157 }
157 return ui::NativeTheme::kNormal; 158 return gfx::NativeTheme::kNormal;
158 } 159 }
159 160
160 void ExampleNativeThemeButton::GetExtraParams( 161 void ExampleNativeThemeButton::GetExtraParams(
161 ui::NativeTheme::ExtraParams* params) const { 162 gfx::NativeTheme::ExtraParams* params) const {
162 163
163 params->button.checked = is_checked_; 164 params->button.checked = is_checked_;
164 params->button.indeterminate = is_indeterminate_; 165 params->button.indeterminate = is_indeterminate_;
165 params->button.is_default = false; 166 params->button.is_default = false;
166 params->button.has_border = false; 167 params->button.has_border = false;
167 params->button.classic_state = 0; 168 params->button.classic_state = 0;
168 params->button.background_color = SkColorSetARGB(0, 0, 0, 0); 169 params->button.background_color = SkColorSetARGB(0, 0, 0, 0);
169 } 170 }
170 171
171 const ui::Animation* ExampleNativeThemeButton::GetThemeAnimation() const { 172 const ui::Animation* ExampleNativeThemeButton::GetThemeAnimation() const {
172 return cb_state_->selected_index() <= 3 ? NULL : hover_animation_.get(); 173 return cb_state_->selected_index() <= 3 ? NULL : hover_animation_.get();
173 } 174 }
174 175
175 ui::NativeTheme::State ExampleNativeThemeButton::GetBackgroundThemeState( 176 gfx::NativeTheme::State ExampleNativeThemeButton::GetBackgroundThemeState(
176 ui::NativeTheme::ExtraParams* params) const { 177 gfx::NativeTheme::ExtraParams* params) const {
177 GetExtraParams(params); 178 GetExtraParams(params);
178 return ui::NativeTheme::kNormal; 179 return gfx::NativeTheme::kNormal;
179 } 180 }
180 181
181 ui::NativeTheme::State ExampleNativeThemeButton::GetForegroundThemeState( 182 gfx::NativeTheme::State ExampleNativeThemeButton::GetForegroundThemeState(
182 ui::NativeTheme::ExtraParams* params) const { 183 gfx::NativeTheme::ExtraParams* params) const {
183 GetExtraParams(params); 184 GetExtraParams(params);
184 return ui::NativeTheme::kHovered; 185 return gfx::NativeTheme::kHovered;
185 } 186 }
186 187
187 gfx::Size ExampleNativeThemeButton::GetPreferredSize() { 188 gfx::Size ExampleNativeThemeButton::GetPreferredSize() {
188 return painter_.get() == NULL ? gfx::Size() : painter_->GetPreferredSize(); 189 return painter_.get() == NULL ? gfx::Size() : painter_->GetPreferredSize();
189 } 190 }
190 191
191 void ExampleNativeThemeButton::OnPaintBackground(gfx::Canvas* canvas) { 192 void ExampleNativeThemeButton::OnPaintBackground(gfx::Canvas* canvas) {
192 // Fill the background with a known colour so that we know where the bounds 193 // Fill the background with a known colour so that we know where the bounds
193 // of the View are. 194 // of the View are.
194 canvas->FillRect(GetLocalBounds(), SkColorSetRGB(255, 128, 128)); 195 canvas->FillRect(GetLocalBounds(), SkColorSetRGB(255, 128, 128));
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 layout->AddPaddingRow(0, 8); 250 layout->AddPaddingRow(0, 8);
250 } 251 }
251 252
252 void NativeThemeButtonExample::ButtonPressed(Button* sender, 253 void NativeThemeButtonExample::ButtonPressed(Button* sender,
253 const Event& event) { 254 const Event& event) {
254 PrintStatus(button_->MessWithState().c_str()); 255 PrintStatus(button_->MessWithState().c_str());
255 } 256 }
256 257
257 } // namespace examples 258 } // namespace examples
258 } // namespace views 259 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/examples/native_theme_button_example.h ('k') | ui/views/examples/native_theme_checkbox_example.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698