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

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

Issue 10103019: views: Use NOTREACHED() where appropriate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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
« no previous file with comments | « ui/gfx/native_theme_win.cc ('k') | no next file » | 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) 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 gfx::NativeTheme::kPushButton: 66 case gfx::NativeTheme::kPushButton:
67 message = "Pressed! count:%d"; 67 message = "Pressed! count:%d";
68 break; 68 break;
69 case gfx::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 gfx::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 83 if (is_checked_)
84 message = is_checked_ ? "Checked! count:%d" : 84 message = "Checked! count:%d";
85 is_indeterminate_ ? "Indeterminate! count:%d" : "Unchecked! count:%d"; 85 else if (is_indeterminate_)
86 break; 86 message = "Indeterminate! count:%d";
87 default: 87 else
88 DCHECK(false); 88 message = "Unchecked! count:%d";
89 break;
90 default:
91 NOTREACHED();
89 } 92 }
90 93
91 return base::StringPrintf(message, ++count_); 94 return base::StringPrintf(message, ++count_);
92 } 95 }
93 96
94 void ExampleNativeThemeButton::OnSelectedIndexChanged(Combobox* combobox) { 97 void ExampleNativeThemeButton::OnSelectedIndexChanged(Combobox* combobox) {
95 SchedulePaint(); 98 SchedulePaint();
96 } 99 }
97 100
98 gfx::NativeTheme::Part ExampleNativeThemeButton::GetThemePart() const { 101 gfx::NativeTheme::Part ExampleNativeThemeButton::GetThemePart() const {
99 switch (cb_part_->selected_index()) { 102 switch (cb_part_->selected_index()) {
100 case 0: 103 case 0:
101 return gfx::NativeTheme::kPushButton; 104 return gfx::NativeTheme::kPushButton;
102 case 1: 105 case 1:
103 return gfx::NativeTheme::kRadio; 106 return gfx::NativeTheme::kRadio;
104 case 2: 107 case 2:
105 return gfx::NativeTheme::kCheckbox; 108 return gfx::NativeTheme::kCheckbox;
106 default: 109 default:
107 DCHECK(false); 110 NOTREACHED();
108 } 111 }
109 return gfx::NativeTheme::kPushButton; 112 return gfx::NativeTheme::kPushButton;
110 } 113 }
111 114
112 gfx::Rect ExampleNativeThemeButton::GetThemePaintRect() const { 115 gfx::Rect ExampleNativeThemeButton::GetThemePaintRect() const {
113 gfx::NativeTheme::ExtraParams extra; 116 gfx::NativeTheme::ExtraParams extra;
114 gfx::NativeTheme::State state = GetThemeState(&extra); 117 gfx::NativeTheme::State state = GetThemeState(&extra);
115 gfx::Size size(gfx::NativeTheme::instance()->GetPartSize(GetThemePart(), 118 gfx::Size size(gfx::NativeTheme::instance()->GetPartSize(GetThemePart(),
116 state, 119 state,
117 extra)); 120 extra));
(...skipping 11 matching lines...) Expand all
129 switch (state()) { 132 switch (state()) {
130 case BS_DISABLED: 133 case BS_DISABLED:
131 return gfx::NativeTheme::kDisabled; 134 return gfx::NativeTheme::kDisabled;
132 case BS_NORMAL: 135 case BS_NORMAL:
133 return gfx::NativeTheme::kNormal; 136 return gfx::NativeTheme::kNormal;
134 case BS_HOT: 137 case BS_HOT:
135 return gfx::NativeTheme::kHovered; 138 return gfx::NativeTheme::kHovered;
136 case BS_PUSHED: 139 case BS_PUSHED:
137 return gfx::NativeTheme::kPressed; 140 return gfx::NativeTheme::kPressed;
138 default: 141 default:
139 DCHECK(false); 142 NOTREACHED();
140 } 143 }
141 } 144 }
142 145
143 switch (selected) { 146 switch (selected) {
144 case 0: 147 case 0:
145 return gfx::NativeTheme::kDisabled; 148 return gfx::NativeTheme::kDisabled;
146 case 1: 149 case 1:
147 return gfx::NativeTheme::kNormal; 150 return gfx::NativeTheme::kNormal;
148 case 2: 151 case 2:
149 return gfx::NativeTheme::kHovered; 152 return gfx::NativeTheme::kHovered;
150 case 3: 153 case 3:
151 return gfx::NativeTheme::kPressed; 154 return gfx::NativeTheme::kPressed;
152 default: 155 default:
153 DCHECK(false); 156 NOTREACHED();
154 } 157 }
155 return gfx::NativeTheme::kNormal; 158 return gfx::NativeTheme::kNormal;
156 } 159 }
157 160
158 void ExampleNativeThemeButton::GetExtraParams( 161 void ExampleNativeThemeButton::GetExtraParams(
159 gfx::NativeTheme::ExtraParams* params) const { 162 gfx::NativeTheme::ExtraParams* params) const {
160 163
161 params->button.checked = is_checked_; 164 params->button.checked = is_checked_;
162 params->button.indeterminate = is_indeterminate_; 165 params->button.indeterminate = is_indeterminate_;
163 params->button.is_default = false; 166 params->button.is_default = false;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 layout->AddPaddingRow(0, 8); 250 layout->AddPaddingRow(0, 8);
248 } 251 }
249 252
250 void NativeThemeButtonExample::ButtonPressed(Button* sender, 253 void NativeThemeButtonExample::ButtonPressed(Button* sender,
251 const Event& event) { 254 const Event& event) {
252 PrintStatus(button_->MessWithState().c_str()); 255 PrintStatus(button_->MessWithState().c_str());
253 } 256 }
254 257
255 } // namespace examples 258 } // namespace examples
256 } // namespace views 259 } // namespace views
OLDNEW
« no previous file with comments | « ui/gfx/native_theme_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698