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

Side by Side Diff: ui/views/controls/button/image_button.h

Issue 10437006: Converts ui/views/controls, ui/views/examples, ui/base/models to ImageSkia (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased 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 #ifndef UI_VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ 5 #ifndef UI_VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_
6 #define UI_VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ 6 #define UI_VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/gtest_prod_util.h" 9 #include "base/gtest_prod_util.h"
10 #include "third_party/skia/include/core/SkBitmap.h"
11 #include "ui/gfx/image/image_skia.h" 10 #include "ui/gfx/image/image_skia.h"
12 #include "ui/views/controls/button/custom_button.h" 11 #include "ui/views/controls/button/custom_button.h"
13 12
14 namespace views { 13 namespace views {
15 14
16 // An image button. 15 // An image button.
17 16
18 // Note that this type of button is not focusable by default and will not be 17 // Note that this type of button is not focusable by default and will not be
19 // part of the focus chain. Call set_focusable(true) to make it part of the 18 // part of the focus chain. Call set_focusable(true) to make it part of the
20 // focus chain. 19 // focus chain.
(...skipping 18 matching lines...) Expand all
39 // Set the image the button should use for the provided state. 38 // Set the image the button should use for the provided state.
40 virtual void SetImage(ButtonState state, const gfx::ImageSkia* image); 39 virtual void SetImage(ButtonState state, const gfx::ImageSkia* image);
41 40
42 // Set the background details. 41 // Set the background details.
43 void SetBackground(SkColor color, 42 void SetBackground(SkColor color,
44 const gfx::ImageSkia* image, 43 const gfx::ImageSkia* image,
45 const gfx::ImageSkia* mask); 44 const gfx::ImageSkia* mask);
46 45
47 // Set an |image| to draw on top of the normal / hot / pushed image. 46 // Set an |image| to draw on top of the normal / hot / pushed image.
48 // Pass NULL for no image. 47 // Pass NULL for no image.
49 void SetOverlayImage(const SkBitmap* image); 48 void SetOverlayImage(const gfx::ImageSkia* image);
50 49
51 // Sets how the image is laid out within the button's bounds. 50 // Sets how the image is laid out within the button's bounds.
52 void SetImageAlignment(HorizontalAlignment h_align, 51 void SetImageAlignment(HorizontalAlignment h_align,
53 VerticalAlignment v_align); 52 VerticalAlignment v_align);
54 53
55 // Overridden from View: 54 // Overridden from View:
56 virtual gfx::Size GetPreferredSize() OVERRIDE; 55 virtual gfx::Size GetPreferredSize() OVERRIDE;
57 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 56 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
58 57
59 // Sets preferred size, so it could be correctly positioned in layout even if 58 // Sets preferred size, so it could be correctly positioned in layout even if
60 // it is NULL. 59 // it is NULL.
61 void SetPreferredSize(const gfx::Size& preferred_size) { 60 void SetPreferredSize(const gfx::Size& preferred_size) {
62 preferred_size_ = preferred_size; 61 preferred_size_ = preferred_size;
63 } 62 }
64 63
65 protected: 64 protected:
66 // Returns the image to paint. This is invoked from paint and returns a value 65 // Returns the image to paint. This is invoked from paint and returns a value
67 // from images. 66 // from images.
68 virtual SkBitmap GetImageToPaint(); 67 virtual gfx::ImageSkia GetImageToPaint();
69 68
70 // The images used to render the different states of this button. 69 // The images used to render the different states of this button.
71 SkBitmap images_[BS_COUNT]; 70 gfx::ImageSkia images_[BS_COUNT];
72 71
73 // The background image. 72 // The background image.
74 SkBitmap background_image_; 73 gfx::ImageSkia background_image_;
75 74
76 // Image to draw on top of normal / hot / pushed image. Usually empty. 75 // Image to draw on top of normal / hot / pushed image. Usually empty.
77 SkBitmap overlay_image_; 76 gfx::ImageSkia overlay_image_;
78 77
79 private: 78 private:
80 FRIEND_TEST_ALL_PREFIXES(ImageButtonTest, Basics); 79 FRIEND_TEST_ALL_PREFIXES(ImageButtonTest, Basics);
81 80
82 // Image alignment. 81 // Image alignment.
83 HorizontalAlignment h_alignment_; 82 HorizontalAlignment h_alignment_;
84 VerticalAlignment v_alignment_; 83 VerticalAlignment v_alignment_;
85 gfx::Size preferred_size_; 84 gfx::Size preferred_size_;
86 85
87 DISALLOW_COPY_AND_ASSIGN(ImageButton); 86 DISALLOW_COPY_AND_ASSIGN(ImageButton);
(...skipping 27 matching lines...) Expand all
115 const gfx::ImageSkia* image) OVERRIDE; 114 const gfx::ImageSkia* image) OVERRIDE;
116 115
117 // Overridden from View: 116 // Overridden from View:
118 virtual bool GetTooltipText(const gfx::Point& p, 117 virtual bool GetTooltipText(const gfx::Point& p,
119 string16* tooltip) const OVERRIDE; 118 string16* tooltip) const OVERRIDE;
120 119
121 private: 120 private:
122 // The parent class's images_ member is used for the current images, 121 // The parent class's images_ member is used for the current images,
123 // and this array is used to hold the alternative images. 122 // and this array is used to hold the alternative images.
124 // We swap between the two when toggling. 123 // We swap between the two when toggling.
125 SkBitmap alternate_images_[BS_COUNT]; 124 gfx::ImageSkia alternate_images_[BS_COUNT];
126 125
127 // True if the button is currently toggled. 126 // True if the button is currently toggled.
128 bool toggled_; 127 bool toggled_;
129 128
130 // The parent class's tooltip_text_ is displayed when not toggled, and 129 // The parent class's tooltip_text_ is displayed when not toggled, and
131 // this one is shown when toggled. 130 // this one is shown when toggled.
132 string16 toggled_tooltip_text_; 131 string16 toggled_tooltip_text_;
133 132
134 DISALLOW_COPY_AND_ASSIGN(ToggleImageButton); 133 DISALLOW_COPY_AND_ASSIGN(ToggleImageButton);
135 }; 134 };
136 135
137 } // namespace views 136 } // namespace views
138 137
139 #endif // UI_VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_ 138 #endif // UI_VIEWS_CONTROLS_BUTTON_IMAGE_BUTTON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698