| OLD | NEW |
| 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 "views/examples/native_theme_button_example.h" | 5 #include "views/examples/native_theme_button_example.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "ui/base/animation/throb_animation.h" | 10 #include "ui/base/animation/throb_animation.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 return gfx::NativeTheme::kRadio; | 130 return gfx::NativeTheme::kRadio; |
| 131 case 2: | 131 case 2: |
| 132 return gfx::NativeTheme::kCheckbox; | 132 return gfx::NativeTheme::kCheckbox; |
| 133 default: | 133 default: |
| 134 DCHECK(false); | 134 DCHECK(false); |
| 135 } | 135 } |
| 136 return gfx::NativeTheme::kPushButton; | 136 return gfx::NativeTheme::kPushButton; |
| 137 } | 137 } |
| 138 | 138 |
| 139 gfx::Rect ExampleNativeThemeButton::GetThemePaintRect() const { | 139 gfx::Rect ExampleNativeThemeButton::GetThemePaintRect() const { |
| 140 return GetLocalBounds(); | 140 gfx::NativeTheme::ExtraParams extra; |
| 141 gfx::NativeTheme::State state = GetThemeState(&extra); |
| 142 gfx::Size size(gfx::NativeTheme::instance()->GetPartSize(GetThemePart(), |
| 143 state, |
| 144 extra)); |
| 145 gfx::Rect rect(size); |
| 146 rect.set_x(GetMirroredXForRect(rect)); |
| 147 return rect; |
| 141 } | 148 } |
| 142 | 149 |
| 143 gfx::NativeTheme::State ExampleNativeThemeButton::GetThemeState( | 150 gfx::NativeTheme::State ExampleNativeThemeButton::GetInternalState() const { |
| 144 gfx::NativeTheme::ExtraParams* params) const { | |
| 145 GetExtraParams(params); | |
| 146 | |
| 147 int selected = cb_state_->selected_item(); | 151 int selected = cb_state_->selected_item(); |
| 148 if (selected > 3) { | 152 if (selected > 3) { |
| 149 switch(state()) { | 153 switch(state()) { |
| 150 case BS_DISABLED: | 154 case BS_DISABLED: |
| 151 return gfx::NativeTheme::kDisabled; | 155 return gfx::NativeTheme::kDisabled; |
| 152 case BS_NORMAL: | 156 case BS_NORMAL: |
| 153 return gfx::NativeTheme::kNormal; | 157 return gfx::NativeTheme::kNormal; |
| 154 case BS_HOT: | 158 case BS_HOT: |
| 155 return gfx::NativeTheme::kHovered; | 159 return gfx::NativeTheme::kHovered; |
| 156 case BS_PUSHED: | 160 case BS_PUSHED: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 168 case 2: | 172 case 2: |
| 169 return gfx::NativeTheme::kHovered; | 173 return gfx::NativeTheme::kHovered; |
| 170 case 3: | 174 case 3: |
| 171 return gfx::NativeTheme::kPressed; | 175 return gfx::NativeTheme::kPressed; |
| 172 default: | 176 default: |
| 173 DCHECK(false); | 177 DCHECK(false); |
| 174 } | 178 } |
| 175 return gfx::NativeTheme::kNormal; | 179 return gfx::NativeTheme::kNormal; |
| 176 } | 180 } |
| 177 | 181 |
| 182 gfx::NativeTheme::State ExampleNativeThemeButton::GetThemeState( |
| 183 gfx::NativeTheme::ExtraParams* params) const { |
| 184 GetExtraParams(params); |
| 185 return GetInternalState(); |
| 186 } |
| 187 |
| 178 void ExampleNativeThemeButton::GetExtraParams( | 188 void ExampleNativeThemeButton::GetExtraParams( |
| 179 gfx::NativeTheme::ExtraParams* params) const { | 189 gfx::NativeTheme::ExtraParams* params) const { |
| 180 | 190 |
| 181 params->button.checked = is_checked_; | 191 params->button.checked = is_checked_; |
| 182 params->button.indeterminate = is_indeterminate_; | 192 params->button.indeterminate = is_indeterminate_; |
| 183 params->button.is_default = false; | 193 params->button.is_default = false; |
| 184 params->button.has_border = false; | 194 params->button.has_border = false; |
| 185 params->button.classic_state = 0; | 195 params->button.classic_state = 0; |
| 186 params->button.background_color = SkColorSetARGB(0, 0, 0, 0); | 196 params->button.background_color = SkColorSetARGB(0, 0, 0, 0); |
| 197 |
| 198 #if defined(OS_WIN) |
| 199 gfx::NativeTheme::Part part = GetThemePart(); |
| 200 switch(part) { |
| 201 case gfx::NativeTheme::kPushButton: |
| 202 params->button.classic_state = DFCS_BUTTONPUSH; |
| 203 break; |
| 204 case gfx::NativeTheme::kRadio: |
| 205 params->button.classic_state = DFCS_BUTTONRADIO; |
| 206 params->button.classic_state |= is_checked_ ? DFCS_CHECKED : 0; |
| 207 break; |
| 208 case gfx::NativeTheme::kCheckbox: |
| 209 params->button.classic_state = DFCS_BUTTONCHECK; |
| 210 params->button.classic_state |= is_checked_ ? DFCS_CHECKED : 0; |
| 211 break; |
| 212 } |
| 213 |
| 214 gfx::NativeTheme::State state = GetInternalState(); |
| 215 switch(state) { |
| 216 case gfx::NativeTheme::kDisabled: |
| 217 params->button.classic_state |= DFCS_INACTIVE; |
| 218 break; |
| 219 case gfx::NativeTheme::kNormal: |
| 220 break; |
| 221 case gfx::NativeTheme::kHovered: |
| 222 break; |
| 223 case gfx::NativeTheme::kPressed: |
| 224 params->button.classic_state |= DFCS_PUSHED; |
| 225 break; |
| 226 default: |
| 227 DCHECK(false); |
| 228 } |
| 229 #endif |
| 187 } | 230 } |
| 188 | 231 |
| 189 const ui::Animation* ExampleNativeThemeButton::GetThemeAnimation() const { | 232 const ui::Animation* ExampleNativeThemeButton::GetThemeAnimation() const { |
| 190 int selected = cb_state_->selected_item(); | 233 int selected = cb_state_->selected_item(); |
| 191 return selected <= 3 ? NULL : hover_animation_.get(); | 234 return selected <= 3 ? NULL : hover_animation_.get(); |
| 192 } | 235 } |
| 193 | 236 |
| 194 gfx::NativeTheme::State ExampleNativeThemeButton::GetBackgroundThemeState( | 237 gfx::NativeTheme::State ExampleNativeThemeButton::GetBackgroundThemeState( |
| 195 gfx::NativeTheme::ExtraParams* params) const { | 238 gfx::NativeTheme::ExtraParams* params) const { |
| 196 GetExtraParams(params); | 239 GetExtraParams(params); |
| 240 #if defined(OS_WIN) |
| 241 params->button.classic_state &= ~(DFCS_PUSHED | DFCS_INACTIVE); |
| 242 #endif |
| 197 return gfx::NativeTheme::kNormal; | 243 return gfx::NativeTheme::kNormal; |
| 198 } | 244 } |
| 199 | 245 |
| 200 gfx::NativeTheme::State ExampleNativeThemeButton::GetForegroundThemeState( | 246 gfx::NativeTheme::State ExampleNativeThemeButton::GetForegroundThemeState( |
| 201 gfx::NativeTheme::ExtraParams* params) const { | 247 gfx::NativeTheme::ExtraParams* params) const { |
| 202 GetExtraParams(params); | 248 GetExtraParams(params); |
| 249 #if defined(OS_WIN) |
| 250 params->button.classic_state &= ~(DFCS_PUSHED | DFCS_INACTIVE); |
| 251 #endif |
| 203 return gfx::NativeTheme::kHovered; | 252 return gfx::NativeTheme::kHovered; |
| 204 } | 253 } |
| 205 | 254 |
| 206 gfx::Size ExampleNativeThemeButton::GetPreferredSize() { | 255 gfx::Size ExampleNativeThemeButton::GetPreferredSize() { |
| 207 return painter_.get() == NULL ? gfx::Size() : painter_->GetPreferredSize(); | 256 return painter_.get() == NULL ? gfx::Size() : painter_->GetPreferredSize(); |
| 208 } | 257 } |
| 209 | 258 |
| 210 void ExampleNativeThemeButton::OnPaintBackground(gfx::Canvas* canvas) { | 259 void ExampleNativeThemeButton::OnPaintBackground(gfx::Canvas* canvas) { |
| 211 // Fill the background with a known colour so that we know where the bounds | 260 // Fill the background with a known colour so that we know where the bounds |
| 212 // of the View are. | 261 // of the View are. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 318 |
| 270 layout->AddPaddingRow(0, 8); | 319 layout->AddPaddingRow(0, 8); |
| 271 } | 320 } |
| 272 | 321 |
| 273 void NativeThemeButtonExample::ButtonPressed(views::Button* sender, | 322 void NativeThemeButtonExample::ButtonPressed(views::Button* sender, |
| 274 const views::Event& event) { | 323 const views::Event& event) { |
| 275 PrintStatus(button_->MessWithState().c_str()); | 324 PrintStatus(button_->MessWithState().c_str()); |
| 276 } | 325 } |
| 277 | 326 |
| 278 } // namespace examples | 327 } // namespace examples |
| OLD | NEW |