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

Side by Side Diff: ui/views/controls/scrollbar/bitmap_scroll_bar.cc

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 #include "ui/views/controls/scrollbar/bitmap_scroll_bar.h" 5 #include "ui/views/controls/scrollbar/bitmap_scroll_bar.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/string16.h" 12 #include "base/string16.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "grit/ui_strings.h" 15 #include "grit/ui_strings.h"
16 #include "third_party/skia/include/core/SkBitmap.h"
17 #include "ui/base/keycodes/keyboard_codes.h" 16 #include "ui/base/keycodes/keyboard_codes.h"
18 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/gfx/canvas.h" 18 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/image/image_skia.h"
20 #include "ui/views/controls/menu/menu.h" 20 #include "ui/views/controls/menu/menu.h"
21 #include "ui/views/controls/scroll_view.h" 21 #include "ui/views/controls/scroll_view.h"
22 #include "ui/views/controls/scrollbar/base_scroll_bar_thumb.h" 22 #include "ui/views/controls/scrollbar/base_scroll_bar_thumb.h"
23 #include "ui/views/widget/widget.h" 23 #include "ui/views/widget/widget.h"
24 24
25 #if defined(OS_LINUX) 25 #if defined(OS_LINUX)
26 #include "ui/views/screen.h" 26 #include "ui/views/screen.h"
27 #endif 27 #endif
28 28
29 #undef min 29 #undef min
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 class BitmapScrollBarThumb : public BaseScrollBarThumb { 102 class BitmapScrollBarThumb : public BaseScrollBarThumb {
103 public: 103 public:
104 explicit BitmapScrollBarThumb(BitmapScrollBar* scroll_bar) 104 explicit BitmapScrollBarThumb(BitmapScrollBar* scroll_bar)
105 : BaseScrollBarThumb(scroll_bar), 105 : BaseScrollBarThumb(scroll_bar),
106 scroll_bar_(scroll_bar) { 106 scroll_bar_(scroll_bar) {
107 } 107 }
108 virtual ~BitmapScrollBarThumb() { } 108 virtual ~BitmapScrollBarThumb() { }
109 109
110 // View overrides: 110 // View overrides:
111 virtual gfx::Size GetPreferredSize() OVERRIDE { 111 virtual gfx::Size GetPreferredSize() OVERRIDE {
112 return gfx::Size(background_bitmap()->width(), 112 return gfx::Size(background_image()->width(),
113 start_cap_bitmap()->height() + 113 start_cap_image()->height() +
114 end_cap_bitmap()->height() + 114 end_cap_image()->height() +
115 grippy_bitmap()->height()); 115 grippy_image()->height());
116 } 116 }
117 117
118 protected: 118 protected:
119 // View overrides: 119 // View overrides:
120 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { 120 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
121 canvas->DrawBitmapInt(*start_cap_bitmap(), 0, 0); 121 canvas->DrawBitmapInt(*start_cap_image(), 0, 0);
122 int top_cap_height = start_cap_bitmap()->height(); 122 int top_cap_height = start_cap_image()->height();
123 int bottom_cap_height = end_cap_bitmap()->height(); 123 int bottom_cap_height = end_cap_image()->height();
124 int thumb_body_height = height() - top_cap_height - bottom_cap_height; 124 int thumb_body_height = height() - top_cap_height - bottom_cap_height;
125 canvas->TileImageInt(*background_bitmap(), 0, top_cap_height, 125 canvas->TileImageInt(*background_image(), 0, top_cap_height,
126 background_bitmap()->width(), thumb_body_height); 126 background_image()->width(), thumb_body_height);
127 canvas->DrawBitmapInt(*end_cap_bitmap(), 0, 127 canvas->DrawBitmapInt(*end_cap_image(), 0,
128 height() - bottom_cap_height); 128 height() - bottom_cap_height);
129 129
130 // Paint the grippy over the track. 130 // Paint the grippy over the track.
131 int grippy_x = (width() - grippy_bitmap()->width()) / 2; 131 int grippy_x = (width() - grippy_image()->width()) / 2;
132 int grippy_y = (thumb_body_height - grippy_bitmap()->height()) / 2; 132 int grippy_y = (thumb_body_height - grippy_image()->height()) / 2;
133 canvas->DrawBitmapInt(*grippy_bitmap(), grippy_x, grippy_y); 133 canvas->DrawBitmapInt(*grippy_image(), grippy_x, grippy_y);
134 } 134 }
135 135
136 private: 136 private:
137 // Returns the image rendered at the start of the thumb. 137 // Returns the image rendered at the start of the thumb.
138 gfx::ImageSkia* start_cap_bitmap() const { 138 gfx::ImageSkia* start_cap_image() const {
139 return scroll_bar_->images_[BitmapScrollBar::THUMB_START_CAP][GetState()]; 139 return scroll_bar_->images_[BitmapScrollBar::THUMB_START_CAP][GetState()];
140 } 140 }
141 141
142 // Returns the image rendered at the end of the thumb. 142 // Returns the image rendered at the end of the thumb.
143 gfx::ImageSkia* end_cap_bitmap() const { 143 gfx::ImageSkia* end_cap_image() const {
144 return scroll_bar_->images_[BitmapScrollBar::THUMB_END_CAP][GetState()]; 144 return scroll_bar_->images_[BitmapScrollBar::THUMB_END_CAP][GetState()];
145 } 145 }
146 146
147 // Returns the image that is tiled in the background of the thumb between 147 // Returns the image that is tiled in the background of the thumb between
148 // the start and the end caps. 148 // the start and the end caps.
149 gfx::ImageSkia* background_bitmap() const { 149 gfx::ImageSkia* background_image() const {
150 return scroll_bar_->images_[BitmapScrollBar::THUMB_MIDDLE][GetState()]; 150 return scroll_bar_->images_[BitmapScrollBar::THUMB_MIDDLE][GetState()];
151 } 151 }
152 152
153 // Returns the image that is rendered in the middle of the thumb 153 // Returns the image that is rendered in the middle of the thumb
154 // transparently over the background bitmap. 154 // transparently over the background image.
155 gfx::ImageSkia* grippy_bitmap() const { 155 gfx::ImageSkia* grippy_image() const {
156 return scroll_bar_->images_[BitmapScrollBar::THUMB_GRIPPY] 156 return scroll_bar_->images_[BitmapScrollBar::THUMB_GRIPPY]
157 [CustomButton::BS_NORMAL]; 157 [CustomButton::BS_NORMAL];
158 } 158 }
159 159
160 // The BitmapScrollBar that owns us. 160 // The BitmapScrollBar that owns us.
161 BitmapScrollBar* scroll_bar_; 161 BitmapScrollBar* scroll_bar_;
162 162
163 DISALLOW_COPY_AND_ASSIGN(BitmapScrollBarThumb); 163 DISALLOW_COPY_AND_ASSIGN(BitmapScrollBarThumb);
164 }; 164 };
165 165
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 next_button_->SetBounds(0, 0, 0, 0); 258 next_button_->SetBounds(0, 0, 0, 0);
259 } 259 }
260 260
261 BaseScrollBarThumb* thumb = GetThumb(); 261 BaseScrollBarThumb* thumb = GetThumb();
262 // Size and place the thumb 262 // Size and place the thumb
263 gfx::Size thumb_prefsize = thumb->GetPreferredSize(); 263 gfx::Size thumb_prefsize = thumb->GetPreferredSize();
264 gfx::Rect track_bounds = GetTrackBounds(); 264 gfx::Rect track_bounds = GetTrackBounds();
265 265
266 // Preserve the height/width of the thumb (depending on orientation) as set 266 // Preserve the height/width of the thumb (depending on orientation) as set
267 // by the last call to |Update|, but coerce the width/height to be the 267 // by the last call to |Update|, but coerce the width/height to be the
268 // appropriate value for the bitmaps provided. 268 // appropriate value for the images provided.
269 if (IsHorizontal()) { 269 if (IsHorizontal()) {
270 thumb->SetBounds(thumb->x(), thumb->y(), thumb->width(), 270 thumb->SetBounds(thumb->x(), thumb->y(), thumb->width(),
271 thumb_prefsize.height()); 271 thumb_prefsize.height());
272 } else { 272 } else {
273 thumb->SetBounds(thumb->x(), thumb->y(), thumb_prefsize.width(), 273 thumb->SetBounds(thumb->x(), thumb->y(), thumb_prefsize.width(),
274 thumb->height()); 274 thumb->height());
275 } 275 }
276 276
277 // Hide the thumb if the track isn't tall enough to display even a tiny 277 // Hide the thumb if the track isn't tall enough to display even a tiny
278 // thumb. The user can only use the mousewheel, scroll buttons or keyboard 278 // thumb. The user can only use the mousewheel, scroll buttons or keyboard
(...skipping 22 matching lines...) Expand all
301 301
302 void BitmapScrollBar::ButtonPressed(Button* sender, const views::Event& event) { 302 void BitmapScrollBar::ButtonPressed(Button* sender, const views::Event& event) {
303 if (sender == prev_button_) { 303 if (sender == prev_button_) {
304 ScrollByAmount(SCROLL_PREV_LINE); 304 ScrollByAmount(SCROLL_PREV_LINE);
305 } else if (sender == next_button_) { 305 } else if (sender == next_button_) {
306 ScrollByAmount(SCROLL_NEXT_LINE); 306 ScrollByAmount(SCROLL_NEXT_LINE);
307 } 307 }
308 } 308 }
309 309
310 } // namespace views 310 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698