Commit 3050bfd9 authored by pkasting@chromium.org's avatar pkasting@chromium.org

Lots of random cleanups, mostly for native_theme_win.cc:

* Rename "max state" value to "num states" so it sounds less like it's the
  largest valid state
* Shorten/simplify code
* Reduce indenting
* No else after return
* Use scoping objects where possible
* Return directly out of switches where possible
* Don't handle DCHECK failure
* Omit NOTREACHED messages (not necessary in tracking down bugs)
* "const" goes on same line as last function arg
* Order "disabled/hovered/normal/pressed" cases the same way every time
* Fix spelling errors
* Eliminate unnecessary {}s

BUG=none
TEST=none

Review URL: https://codereview.chromium.org/377423003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282533 0039d316-1c4b-4281-b951-d872f2087c98
parent 78d059fc
......@@ -132,11 +132,11 @@ void ClearAuraTransientParent(GtkWidget* dialog) {
GtkStateType GetGtkState(ui::NativeTheme::State state) {
switch (state) {
case ui::NativeTheme::kDisabled: return GTK_STATE_INSENSITIVE;
case ui::NativeTheme::kHovered: return GTK_STATE_PRELIGHT;
case ui::NativeTheme::kNormal: return GTK_STATE_NORMAL;
case ui::NativeTheme::kPressed: return GTK_STATE_ACTIVE;
case ui::NativeTheme::kMaxState: NOTREACHED() << "Unknown state: " << state;
case ui::NativeTheme::kDisabled: return GTK_STATE_INSENSITIVE;
case ui::NativeTheme::kHovered: return GTK_STATE_PRELIGHT;
case ui::NativeTheme::kNormal: return GTK_STATE_NORMAL;
case ui::NativeTheme::kPressed: return GTK_STATE_ACTIVE;
case ui::NativeTheme::kNumStates: NOTREACHED();
}
return GTK_STATE_NORMAL;
}
......
......@@ -90,7 +90,7 @@ class NATIVE_THEME_EXPORT NativeTheme {
kHovered = 1,
kNormal = 2,
kPressed = 3,
kMaxState = 4,
kNumStates = kPressed + 1,
};
// Each structure below holds extra information needed when painting a given
......
......@@ -29,28 +29,28 @@ namespace ui {
namespace {
const int kScrollbarThumbImages[NativeTheme::kMaxState][9] = {
const int kScrollbarThumbImages[NativeTheme::kNumStates][9] = {
EMPTY_IMAGE_GRID,
IMAGE_GRID(IDR_SCROLLBAR_THUMB_BASE_HOVER),
IMAGE_GRID(IDR_SCROLLBAR_THUMB_BASE_NORMAL),
IMAGE_GRID(IDR_SCROLLBAR_THUMB_BASE_PRESSED)
};
const int kScrollbarArrowButtonImages[NativeTheme::kMaxState][9] = {
const int kScrollbarArrowButtonImages[NativeTheme::kNumStates][9] = {
EMPTY_IMAGE_GRID,
IMAGE_GRID(IDR_SCROLLBAR_ARROW_BUTTON_BASE_HOVER),
IMAGE_GRID(IDR_SCROLLBAR_ARROW_BUTTON_BASE_NORMAL),
IMAGE_GRID(IDR_SCROLLBAR_ARROW_BUTTON_BASE_PRESSED)
};
const uint8 kScrollbarOverlayThumbFillAlphas[NativeTheme::kMaxState] = {
const uint8 kScrollbarOverlayThumbFillAlphas[NativeTheme::kNumStates] = {
0, // Does not matter, will not paint for disabled state.
178, // Hover state, opacity 70%, alpha would be 0.7 * 255.
140, // Normal state, opacity 55%, alpha would be 0.55 * 255.
178 // Pressed state, opacity 70%, alpha would be 0.7 * 255.
};
const uint8 kScrollbarOverlayThumbStrokeAlphas[NativeTheme::kMaxState] = {
const uint8 kScrollbarOverlayThumbStrokeAlphas[NativeTheme::kNumStates] = {
0, // Does not matter, will not paint for disabled state.
51, // Hover state, opacity 20%, alpha would be 0.2 * 255.
38, // Normal state, opacity 15%, alpha would be 0.15 * 255.
......@@ -87,11 +87,10 @@ NativeThemeAura::NativeThemeAura() {
#endif
// Images and alphas declarations assume the following order.
COMPILE_ASSERT(kDisabled == 0, states_unexepctedly_changed);
COMPILE_ASSERT(kHovered == 1, states_unexepctedly_changed);
COMPILE_ASSERT(kNormal == 2, states_unexepctedly_changed);
COMPILE_ASSERT(kPressed == 3, states_unexepctedly_changed);
COMPILE_ASSERT(kMaxState == 4, states_unexepctedly_changed);
COMPILE_ASSERT(kDisabled == 0, states_unexpectedly_changed);
COMPILE_ASSERT(kHovered == 1, states_unexpectedly_changed);
COMPILE_ASSERT(kNormal == 2, states_unexpectedly_changed);
COMPILE_ASSERT(kPressed == 3, states_unexpectedly_changed);
}
NativeThemeAura::~NativeThemeAura() {
......@@ -245,9 +244,9 @@ void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas,
}
NineImagePainter* NativeThemeAura::GetOrCreatePainter(
const int images[kMaxState][9],
const int images[kNumStates][9],
State state,
scoped_ptr<NineImagePainter> painters[kMaxState]) const {
scoped_ptr<NineImagePainter> painters[kNumStates]) const {
if (painters[state])
return painters[state].get();
if (images[state][0] == 0) {
......@@ -269,9 +268,9 @@ void NativeThemeAura::PaintPainter(NineImagePainter* painter,
scoped_ptr<NativeThemeAura::DualPainter> NativeThemeAura::CreateDualPainter(
const int fill_image_ids[9],
const uint8 fill_alphas[kMaxState],
const uint8 fill_alphas[kNumStates],
const int stroke_image_ids[9],
const uint8 stroke_alphas[kMaxState]) const {
const uint8 stroke_alphas[kNumStates]) const {
scoped_ptr<NativeThemeAura::DualPainter> dual_painter(
new NativeThemeAura::DualPainter(CreateNineImagePainter(fill_image_ids),
fill_alphas,
......@@ -317,9 +316,9 @@ void NativeThemeAura::PaintDualPainterTransition(
NativeThemeAura::DualPainter::DualPainter(
scoped_ptr<NineImagePainter> fill_painter,
const uint8 fill_alphas[kMaxState],
const uint8 fill_alphas[kNumStates],
scoped_ptr<NineImagePainter> stroke_painter,
const uint8 stroke_alphas[kMaxState])
const uint8 stroke_alphas[kNumStates])
: fill_painter(fill_painter.Pass()),
fill_alphas(fill_alphas),
stroke_painter(stroke_painter.Pass()),
......
......@@ -63,9 +63,9 @@ class NATIVE_THEME_EXPORT NativeThemeAura : public FallbackTheme {
// necessary. If no image is provided for the specified state the normal state
// images are used.
gfx::NineImagePainter* GetOrCreatePainter(
const int image_ids[kMaxState][9],
const int image_ids[kNumStates][9],
State state,
scoped_ptr<gfx::NineImagePainter> painters[kMaxState]) const;
scoped_ptr<gfx::NineImagePainter> painters[kNumStates]) const;
// Paints |painter| into the canvas using |rect|.
void PaintPainter(gfx::NineImagePainter* painter,
......@@ -75,10 +75,10 @@ class NATIVE_THEME_EXPORT NativeThemeAura : public FallbackTheme {
mutable scoped_ptr<gfx::NineImagePainter> scrollbar_track_painter_;
mutable scoped_ptr<gfx::NineImagePainter>
scrollbar_thumb_painters_[kMaxState];
scrollbar_thumb_painters_[kNumStates];
mutable scoped_ptr<gfx::NineImagePainter>
scrollbar_arrow_button_painters_[kMaxState];
scrollbar_arrow_button_painters_[kNumStates];
private:
struct DualPainter {
......@@ -88,9 +88,9 @@ class NATIVE_THEME_EXPORT NativeThemeAura : public FallbackTheme {
// value associated with each state, so that a DualPainter for overlay
// scrollbar thumb would only need state as input to paint correctly.
DualPainter(scoped_ptr<gfx::NineImagePainter> fill_painter,
const uint8 fill_alphas[kMaxState],
const uint8 fill_alphas[kNumStates],
scoped_ptr<gfx::NineImagePainter> stroke_painter,
const uint8 stroke_alphas[kMaxState]);
const uint8 stroke_alphas[kNumStates]);
~DualPainter();
scoped_ptr<gfx::NineImagePainter> fill_painter;
......@@ -102,9 +102,9 @@ class NATIVE_THEME_EXPORT NativeThemeAura : public FallbackTheme {
// Returns DualPainter from specific fill and stroke, creating if necessary.
scoped_ptr<DualPainter> CreateDualPainter(
const int fill_image_ids[9],
const uint8 fill_alphas[kMaxState],
const uint8 fill_alphas[kNumStates],
const int stroke_image_ids[9],
const uint8 stroke_alphas[kMaxState]) const;
const uint8 stroke_alphas[kNumStates]) const;
// Paints |dualPainter| into the canvas using |rect| and specific alpha.
void PaintDualPainter(DualPainter* dual_painter,
......
This diff is collapsed.
......@@ -15,11 +15,11 @@ namespace views {
// static
Button::ButtonState Button::GetButtonStateFrom(ui::NativeTheme::State state) {
switch (state) {
case ui::NativeTheme::kDisabled: return Button::STATE_DISABLED;
case ui::NativeTheme::kHovered: return Button::STATE_HOVERED;
case ui::NativeTheme::kNormal: return Button::STATE_NORMAL;
case ui::NativeTheme::kPressed: return Button::STATE_PRESSED;
case ui::NativeTheme::kMaxState: NOTREACHED() << "Unknown state: " << state;
case ui::NativeTheme::kDisabled: return Button::STATE_DISABLED;
case ui::NativeTheme::kHovered: return Button::STATE_HOVERED;
case ui::NativeTheme::kNormal: return Button::STATE_NORMAL;
case ui::NativeTheme::kPressed: return Button::STATE_PRESSED;
case ui::NativeTheme::kNumStates: NOTREACHED();
}
return Button::STATE_NORMAL;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment