diff options
author | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-08 08:49:14 +0000 |
---|---|---|
committer | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-08 08:49:14 +0000 |
commit | 47b138b8f731086c7ca2180b878a80c51bf8ad12 (patch) | |
tree | 8db7dc51f201eff36919ae174d917bf5a4d24ce9 /ui/views | |
parent | 0283f3636b68ee14f1df9dc4708bf690a8f2952e (diff) | |
download | chromium_src-47b138b8f731086c7ca2180b878a80c51bf8ad12.zip chromium_src-47b138b8f731086c7ca2180b878a80c51bf8ad12.tar.gz chromium_src-47b138b8f731086c7ca2180b878a80c51bf8ad12.tar.bz2 |
Consolidate ImagePainter and BorderImages.
Remove button-specific BorderImage class and files.
Rewrite ImagePainter using BorderImage-inspired code.
(supports splitting one image or using 9 originals)
Add CreateImageGridPainter static painter function.
Store Painters in text/label button border classes.
Rename BORDER_IMAGES macro to IMAGE_GRID; include braces.
Convert existing BorderImage users to ImagePainter.
Nix unused TextButtonDefaultBorder::copy_normal_set_to_hot_set().
Nix unused |paint_center| argument (true in only use).
BUG=161374
TEST=No button or omnibox border painting regressions.
R=pkasting@chromium.org
TBR=sky@chromium.org
Review URL: https://chromiumcodereview.appspot.com/11466019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171966 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views')
-rw-r--r-- | ui/views/controls/button/border_images.cc | 69 | ||||
-rw-r--r-- | ui/views/controls/button/border_images.h | 52 | ||||
-rw-r--r-- | ui/views/controls/button/label_button_border.cc | 35 | ||||
-rw-r--r-- | ui/views/controls/button/label_button_border.h | 14 | ||||
-rw-r--r-- | ui/views/controls/button/text_button.cc | 25 | ||||
-rw-r--r-- | ui/views/controls/button/text_button.h | 24 | ||||
-rw-r--r-- | ui/views/painter.cc | 171 | ||||
-rw-r--r-- | ui/views/painter.h | 24 | ||||
-rw-r--r-- | ui/views/views.gyp | 2 |
9 files changed, 156 insertions, 260 deletions
diff --git a/ui/views/controls/button/border_images.cc b/ui/views/controls/button/border_images.cc deleted file mode 100644 index 7e617f0..0000000 --- a/ui/views/controls/button/border_images.cc +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/views/controls/button/border_images.h" - -#include "base/logging.h" -#include "grit/ui_resources.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/rect.h" - -namespace views { - -// static -const int BorderImages::kHot[] = { BORDER_IMAGES(IDR_TEXTBUTTON_HOVER) }; -// static -const int BorderImages::kPushed[] = { BORDER_IMAGES(IDR_TEXTBUTTON_PRESSED) }; - -BorderImages::BorderImages() {} - -BorderImages::BorderImages(const int image_ids[]) { - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - top_left_ = *rb.GetImageSkiaNamed(image_ids[0]); - top_ = *rb.GetImageSkiaNamed(image_ids[1]); - top_right_ = *rb.GetImageSkiaNamed(image_ids[2]); - left_ = *rb.GetImageSkiaNamed(image_ids[3]); - center_ = *rb.GetImageSkiaNamed(image_ids[4]); - right_ = *rb.GetImageSkiaNamed(image_ids[5]); - bottom_left_ = *rb.GetImageSkiaNamed(image_ids[6]); - bottom_ = *rb.GetImageSkiaNamed(image_ids[7]); - bottom_right_ = *rb.GetImageSkiaNamed(image_ids[8]); -} - -BorderImages::~BorderImages() {} - -bool BorderImages::IsEmpty() const { - return top_left_.isNull(); -} - -void BorderImages::Paint(gfx::Canvas* canvas, const gfx::Size& size) { - if (IsEmpty()) - return; - - // Images must share widths by column and heights by row as depicted below. - // x0 x1 x2 x3 - // y0__|____|____|____| - // y1__|_tl_|_t__|_tr_| - // y2__|_l__|_c__|_r__| - // y3__|_bl_|_b__|_br_| - const gfx::Rect rect(size); - const int x[] = { rect.x(), rect.x() + top_left_.width(), - rect.right() - top_right_.width(), rect.right() }; - const int y[] = { rect.y(), rect.y() + top_left_.height(), - rect.bottom() - bottom_left_.height(), rect.bottom() }; - - canvas->DrawImageInt(top_left_, x[0], y[0]); - canvas->TileImageInt(top_, x[1], y[0], x[2] - x[1], y[1] - y[0]); - canvas->DrawImageInt(top_right_, x[2], y[0]); - canvas->TileImageInt(left_, x[0], y[1], x[1] - x[0], y[2] - y[1]); - canvas->DrawImageInt(center_, 0, 0, center_.width(), center_.height(), - x[1], y[1], x[2] - x[1], y[2] - y[1], false); - canvas->TileImageInt(right_, x[2], y[1], x[3] - x[2], y[2] - y[1]); - canvas->DrawImageInt(bottom_left_, 0, y[2]); - canvas->TileImageInt(bottom_, x[1], y[2], x[2] - x[1], y[3] - y[2]); - canvas->DrawImageInt(bottom_right_, x[2], y[2]); -} - -} // namespace views diff --git a/ui/views/controls/button/border_images.h b/ui/views/controls/button/border_images.h deleted file mode 100644 index 4909e11..0000000 --- a/ui/views/controls/button/border_images.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_VIEWS_CONTROLS_BUTTON_BORDER_IMAGES_H_ -#define UI_VIEWS_CONTROLS_BUTTON_BORDER_IMAGES_H_ - -#include "ui/gfx/image/image_skia.h" -#include "ui/views/painter.h" -#include "ui/views/views_export.h" - -#define BORDER_IMAGES(x) x ## _TOP_LEFT, x ## _TOP, x ## _TOP_RIGHT, \ - x ## _LEFT, x ## _CENTER, x ## _RIGHT, \ - x ## _BOTTOM_LEFT, x ## _BOTTOM, x ## _BOTTOM_RIGHT, - -namespace views { - -// BorderImages stores and paints the nine images comprising a button border. -// TODO(msw): Merge common "nine-box" code with BubbleBorder, ImagePainter, etc. -// TODO(msw): Stitch border image assets together and use ImagePainter. -class VIEWS_EXPORT BorderImages : public Painter { - public: - // The default hot and pushed button image IDs; normal has none by default. - static const int kHot[]; - static const int kPushed[]; - - BorderImages(); - // |image_ids| must contain 9 image IDs matching the member order below. - explicit BorderImages(const int image_ids[]); - virtual ~BorderImages(); - - // Returns true if the images are empty. - bool IsEmpty() const; - - // Overridden from Painter: - virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) OVERRIDE; - - private: - gfx::ImageSkia top_left_; - gfx::ImageSkia top_; - gfx::ImageSkia top_right_; - gfx::ImageSkia left_; - gfx::ImageSkia center_; - gfx::ImageSkia right_; - gfx::ImageSkia bottom_left_; - gfx::ImageSkia bottom_; - gfx::ImageSkia bottom_right_; -}; - -} // namespace views - -#endif // UI_VIEWS_CONTROLS_BUTTON_BORDER_IMAGES_H_ diff --git a/ui/views/controls/button/label_button_border.cc b/ui/views/controls/button/label_button_border.cc index 5fe6276..b3a4120 100644 --- a/ui/views/controls/button/label_button_border.cc +++ b/ui/views/controls/button/label_button_border.cc @@ -5,6 +5,7 @@ #include "ui/views/controls/button/label_button_border.h" #include "base/logging.h" +#include "grit/ui_resources.h" #include "ui/base/animation/animation.h" #include "ui/gfx/canvas.h" #include "ui/gfx/rect.h" @@ -24,15 +25,19 @@ static const int kPreferredPaddingVertical = 5; static const int kPreferredNativeThemePaddingHorizontal = 12; static const int kPreferredNativeThemePaddingVertical = 5; -views::CustomButton::ButtonState GetButtonState(ui::NativeTheme::State state) { +// The default hot and pushed button image IDs; normal has none by default. +const int kHotImages[] = IMAGE_GRID(IDR_TEXTBUTTON_HOVER); +const int kPushedImages[] = IMAGE_GRID(IDR_TEXTBUTTON_PRESSED); + +CustomButton::ButtonState GetButtonState(ui::NativeTheme::State state) { switch(state) { - case ui::NativeTheme::kDisabled: return views::CustomButton::STATE_DISABLED; - case ui::NativeTheme::kHovered: return views::CustomButton::STATE_HOVERED; - case ui::NativeTheme::kNormal: return views::CustomButton::STATE_NORMAL; - case ui::NativeTheme::kPressed: return views::CustomButton::STATE_PRESSED; + case ui::NativeTheme::kDisabled: return CustomButton::STATE_DISABLED; + case ui::NativeTheme::kHovered: return CustomButton::STATE_HOVERED; + case ui::NativeTheme::kNormal: return CustomButton::STATE_NORMAL; + case ui::NativeTheme::kPressed: return CustomButton::STATE_PRESSED; case ui::NativeTheme::kMaxState: NOTREACHED() << "Unknown state: " << state; } - return views::CustomButton::STATE_NORMAL; + return CustomButton::STATE_NORMAL; } // A helper function to paint the native theme or images as appropriate. @@ -46,14 +51,16 @@ void PaintHelper(LabelButtonBorder* border, if (border->native_theme()) theme->Paint(canvas->sk_canvas(), part, state, rect, extra); else - border->GetImages(GetButtonState(state))->Paint(canvas, rect.size()); + border->GetPainter(GetButtonState(state))->Paint(canvas, rect.size()); } } // namespace LabelButtonBorder::LabelButtonBorder() : native_theme_(false) { - SetImages(CustomButton::STATE_HOVERED, BorderImages(BorderImages::kHot)); - SetImages(CustomButton::STATE_PRESSED, BorderImages(BorderImages::kPushed)); + SetPainter(CustomButton::STATE_HOVERED, + Painter::CreateImageGridPainter(kHotImages)); + SetPainter(CustomButton::STATE_PRESSED, + Painter::CreateImageGridPainter(kPushedImages)); } LabelButtonBorder::~LabelButtonBorder() {} @@ -101,13 +108,13 @@ gfx::Insets LabelButtonBorder::GetInsets() const { } } -BorderImages* LabelButtonBorder::GetImages(CustomButton::ButtonState state) { - return &images_[state]; +Painter* LabelButtonBorder::GetPainter(CustomButton::ButtonState state) { + return painters_[state].get(); } -void LabelButtonBorder::SetImages(CustomButton::ButtonState state, - const BorderImages& set) { - images_[state] = set; +void LabelButtonBorder::SetPainter(CustomButton::ButtonState state, + Painter* painter) { + painters_[state].reset(painter); } } // namespace views diff --git a/ui/views/controls/button/label_button_border.h b/ui/views/controls/button/label_button_border.h index 696ca3d..3bb4374 100644 --- a/ui/views/controls/button/label_button_border.h +++ b/ui/views/controls/button/label_button_border.h @@ -7,9 +7,10 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" #include "ui/views/border.h" -#include "ui/views/controls/button/border_images.h" #include "ui/views/controls/button/custom_button.h" +#include "ui/views/painter.h" namespace views { @@ -26,13 +27,14 @@ class VIEWS_EXPORT LabelButtonBorder : public Border { virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE; virtual gfx::Insets GetInsets() const OVERRIDE; - // Get or set the images shown for the specified button state. - BorderImages* GetImages(CustomButton::ButtonState state); - void SetImages(CustomButton::ButtonState state, const BorderImages& images); + // Get or set the painter used for the specified button state. + // LabelButtonBorder takes and retains ownership of |painter|. + Painter* GetPainter(CustomButton::ButtonState state); + void SetPainter(CustomButton::ButtonState state, Painter* painter); private: - // The images shown for each button state. - BorderImages images_[CustomButton::STATE_COUNT]; + // The painters used for each button state. + scoped_ptr<Painter> painters_[CustomButton::STATE_COUNT]; // A flag controlling native (true) or Views theme styling; false by default. bool native_theme_; diff --git a/ui/views/controls/button/text_button.cc b/ui/views/controls/button/text_button.cc index b800cf0..0ff4daac 100644 --- a/ui/views/controls/button/text_button.cc +++ b/ui/views/controls/button/text_button.cc @@ -54,6 +54,10 @@ const int kMinWidthDLUs = 50; const int kMinHeightDLUs = 14; #endif +// The default hot and pushed button image IDs; normal has none by default. +const int kHotImages[] = IMAGE_GRID(IDR_TEXTBUTTON_HOVER); +const int kPushedImages[] = IMAGE_GRID(IDR_TEXTBUTTON_PRESSED); + } // namespace // static @@ -99,12 +103,10 @@ const TextButtonBorder* TextButtonBorder::AsTextButtonBorder() const { TextButtonDefaultBorder::TextButtonDefaultBorder() : vertical_padding_(kPreferredPaddingVertical) { - set_hot_set(BorderImages(BorderImages::kHot)); - set_pushed_set(BorderImages(BorderImages::kPushed)); - SetInsets(gfx::Insets(vertical_padding_, - kPreferredPaddingHorizontal, - vertical_padding_, - kPreferredPaddingHorizontal)); + set_hot_painter(Painter::CreateImageGridPainter(kHotImages)); + set_pushed_painter(Painter::CreateImageGridPainter(kPushedImages)); + SetInsets(gfx::Insets(vertical_padding_, kPreferredPaddingHorizontal, + vertical_padding_, kPreferredPaddingHorizontal)); } TextButtonDefaultBorder::~TextButtonDefaultBorder() { @@ -119,22 +121,23 @@ void TextButtonDefaultBorder::Paint(const View& view, gfx::Canvas* canvas) { const TextButton* button = static_cast<const TextButton*>(&view); int state = button->state(); - BorderImages* set = &normal_set_; + Painter* painter = normal_painter_.get(); if (button->show_multiple_icon_states() && ((state == TextButton::STATE_HOVERED) || (state == TextButton::STATE_PRESSED))) { - set = (state == TextButton::STATE_HOVERED) ? &hot_set_ : &pushed_set_; + painter = (state == TextButton::STATE_HOVERED) ? + hot_painter_.get() : pushed_painter_.get(); } - if (!set->IsEmpty()) { + if (painter) { if (button->GetAnimation()->is_animating()) { // TODO(pkasting): Really this should crossfade between states so it could // handle the case of having a non-NULL |normal_set_|. canvas->SaveLayerAlpha(static_cast<uint8>( button->GetAnimation()->CurrentValueBetween(0, 255))); - set->Paint(canvas, view.size()); + painter->Paint(canvas, view.size()); canvas->Restore(); } else { - set->Paint(canvas, view.size()); + painter->Paint(canvas, view.size()); } } } diff --git a/ui/views/controls/button/text_button.h b/ui/views/controls/button/text_button.h index bd5a200..e8544a4 100644 --- a/ui/views/controls/button/text_button.h +++ b/ui/views/controls/button/text_button.h @@ -8,14 +8,15 @@ #include <string> #include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" #include "base/string16.h" #include "third_party/skia/include/core/SkColor.h" #include "ui/gfx/font.h" #include "ui/gfx/image/image_skia.h" #include "ui/views/border.h" -#include "ui/views/controls/button/border_images.h" #include "ui/views/controls/button/custom_button.h" #include "ui/views/native_theme_delegate.h" +#include "ui/views/painter.h" namespace views { @@ -64,24 +65,19 @@ class VIEWS_EXPORT TextButtonDefaultBorder : public TextButtonBorder { TextButtonDefaultBorder(); virtual ~TextButtonDefaultBorder(); - // By default STATE_NORMAL is drawn with no border. Call this to instead draw - // it with the same border as the "hot" state. - // TODO(pkasting): You should also call set_animate_on_state_change(false) on - // the button in this case... we should fix this. - void copy_normal_set_to_hot_set() { set_normal_set(hot_set_); } - protected: - void set_normal_set(const BorderImages& set) { normal_set_ = set; } - void set_hot_set(const BorderImages& set) { hot_set_ = set; } - void set_pushed_set(const BorderImages& set) { pushed_set_ = set; } + // TextButtonDefaultBorder takes and retains ownership of these |painter|s. + void set_normal_painter(Painter* painter) { normal_painter_.reset(painter); } + void set_hot_painter(Painter* painter) { hot_painter_.reset(painter); } + void set_pushed_painter(Painter* painter) { pushed_painter_.reset(painter); } private: - // Border: + // Implementation of Border: virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE; - BorderImages normal_set_; - BorderImages hot_set_; - BorderImages pushed_set_; + scoped_ptr<Painter> normal_painter_; + scoped_ptr<Painter> hot_painter_; + scoped_ptr<Painter> pushed_painter_; int vertical_padding_; diff --git a/ui/views/painter.cc b/ui/views/painter.cc index 85468d1..c46854b 100644 --- a/ui/views/painter.cc +++ b/ui/views/painter.cc @@ -11,6 +11,7 @@ #include "ui/gfx/canvas.h" #include "ui/gfx/image/image.h" #include "ui/gfx/image/image_skia.h" +#include "ui/gfx/image/image_skia_operations.h" #include "ui/gfx/insets.h" #include "ui/gfx/point.h" #include "ui/gfx/rect.h" @@ -72,96 +73,92 @@ class GradientPainter : public Painter { DISALLOW_COPY_AND_ASSIGN(GradientPainter); }; - -class ImagePainter : public Painter { +// ImagePainter stores and paints nine images as a scalable grid. +class VIEWS_EXPORT ImagePainter : public Painter { public: - ImagePainter(const gfx::ImageSkia& image, - const gfx::Insets& insets, - bool paint_center) - : image_(image), - insets_(insets), - paint_center_(paint_center) { - DCHECK(image.width() > insets.width() && - image.height() > insets.height()); - } + // Construct an ImagePainter with the specified image resource ids. + // See CreateImageGridPainter()'s comment regarding image ID count and order. + explicit ImagePainter(const int image_ids[]); + // Construct an ImagePainter with the specified image and insets. + ImagePainter(const gfx::ImageSkia& image, const gfx::Insets& insets); - // Paints the images. - virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) OVERRIDE { - if (size.width() == image_.width() && size.height() == image_.height()) { - // Early out if the size we're to render at equals the size of the image. - canvas->DrawImageInt(image_, 0, 0); - return; - } - // Upper left. - canvas->DrawImageInt(image_, 0, 0, insets_.left(), insets_.top(), - 0, 0, insets_.left(), insets_.top(), true); - // Top edge. - canvas->DrawImageInt( - image_, - insets_.left(), 0, image_.width() - insets_.width(), insets_.top(), - insets_.left(), 0, size.width() - insets_.width(), insets_.top(), true); - // Upper right. - canvas->DrawImageInt( - image_, - image_.width() - insets_.right(), 0, insets_.right(), insets_.top(), - size.width() - insets_.right(), 0, insets_.right(), insets_.top(), - true); - // Right edge. - canvas->DrawImageInt( - image_, - image_.width() - insets_.right(), insets_.top(), - insets_.right(), image_.height() - insets_.height(), - size.width() - insets_.right(), insets_.top(), insets_.right(), - size.height() - insets_.height(), true); - // Bottom right. - canvas->DrawImageInt( - image_, - image_.width() - insets_.right(), image_.height() - insets_.bottom(), - insets_.right(), insets_.bottom(), - size.width() - insets_.right(), - size.height() - insets_.bottom(), insets_.right(), - insets_.bottom(), true); - // Bottom edge. - canvas->DrawImageInt( - image_, - insets_.left(), image_.height() - insets_.bottom(), - image_.width() - insets_.width(), insets_.bottom(), - insets_.left(), size.height() - insets_.bottom(), - size.width() - insets_.width(), - insets_.bottom(), true); - // Bottom left. - canvas->DrawImageInt( - image_, - 0, image_.height() - insets_.bottom(), insets_.left(), - insets_.bottom(), - 0, size.height() - insets_.bottom(), insets_.left(), insets_.bottom(), - true); - // Left. - canvas->DrawImageInt( - image_, - 0, insets_.top(), insets_.left(), image_.height() - insets_.height(), - 0, insets_.top(), insets_.left(), size.height() - insets_.height(), - true); - // Center. - if (paint_center_) { - canvas->DrawImageInt( - image_, - insets_.left(), insets_.top(), - image_.width() - insets_.width(), image_.height() - insets_.height(), - insets_.left(), insets_.top(), - size.width() - insets_.width(), size.height() - insets_.height(), - true); - } - } + virtual ~ImagePainter(); + + // Returns true if the images are empty. + bool IsEmpty() const; + + // Overridden from Painter: + virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) OVERRIDE; private: - const gfx::ImageSkia image_; - const gfx::Insets insets_; - bool paint_center_; + // Images must share widths by column and heights by row as depicted below. + // Coordinates along the X and Y axes are used for construction and painting. + // x0 x1 x2 x3 + // y0__|____|____|____| + // y1__|_i0_|_i1_|_i2_| + // y2__|_i3_|_i4_|_i5_| + // y3__|_i6_|_i7_|_i8_| + gfx::ImageSkia images_[9]; DISALLOW_COPY_AND_ASSIGN(ImagePainter); }; +ImagePainter::ImagePainter(const int image_ids[]) { + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); + for (size_t i = 0; i < 9; ++i) + images_[i] = *rb.GetImageSkiaNamed(image_ids[i]); +} + +ImagePainter::ImagePainter(const gfx::ImageSkia& image, + const gfx::Insets& insets) { + DCHECK_GE(image.width(), insets.width()); + DCHECK_GE(image.height(), insets.height()); + + // Extract subsets of the original image to match the |images_| format. + const int x[] = + { 0, insets.left(), image.width() - insets.right(), image.width() }; + const int y[] = + { 0, insets.top(), image.height() - insets.bottom(), image.height() }; + + for (size_t j = 0; j < 3; ++j) { + for (size_t i = 0; i < 3; ++i) { + images_[i + j * 3] = gfx::ImageSkiaOperations::ExtractSubset(image, + gfx::Rect(x[i], y[j], x[i + 1] - x[i], y[j + 1] - y[j])); + } + } +} + +ImagePainter::~ImagePainter() { +} + +bool ImagePainter::IsEmpty() const { + return images_[0].isNull(); +} + +void ImagePainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { + if (IsEmpty()) + return; + + // Paint image subsets in accordance with the |images_| format. + const gfx::Rect rect(size); + const int x[] = { rect.x(), rect.x() + images_[0].width(), + rect.right() - images_[2].width(), rect.right() }; + const int y[] = { rect.y(), rect.y() + images_[0].height(), + rect.bottom() - images_[6].height(), rect.bottom() }; + + canvas->DrawImageInt(images_[0], x[0], y[0]); + canvas->TileImageInt(images_[1], x[1], y[0], x[2] - x[1], y[1] - y[0]); + canvas->DrawImageInt(images_[2], x[2], y[0]); + canvas->TileImageInt(images_[3], x[0], y[1], x[1] - x[0], y[2] - y[1]); + canvas->DrawImageInt( + images_[4], 0, 0, images_[4].width(), images_[4].height(), + x[1], y[1], x[2] - x[1], y[2] - y[1], false); + canvas->TileImageInt(images_[5], x[2], y[1], x[3] - x[2], y[2] - y[1]); + canvas->DrawImageInt(images_[6], 0, y[2]); + canvas->TileImageInt(images_[7], x[1], y[2], x[2] - x[1], y[3] - y[2]); + canvas->DrawImageInt(images_[8], x[2], y[2]); +} + } // namespace // static @@ -202,9 +199,13 @@ Painter* Painter::CreateVerticalMultiColorGradient(SkColor* colors, // static Painter* Painter::CreateImagePainter(const gfx::ImageSkia& image, - const gfx::Insets& insets, - bool paint_center) { - return new ImagePainter(image, insets, paint_center); + const gfx::Insets& insets) { + return new ImagePainter(image, insets); +} + +// static +Painter* Painter::CreateImageGridPainter(const int image_ids[]) { + return new ImagePainter(image_ids); } HorizontalPainter::HorizontalPainter(const int image_resource_names[]) { diff --git a/ui/views/painter.h b/ui/views/painter.h index f430f44..d4b0daa 100644 --- a/ui/views/painter.h +++ b/ui/views/painter.h @@ -18,6 +18,11 @@ class Rect; class Size; } +// A macro to define arrays of IDR constants used with CreateImageGridPainter. +#define IMAGE_GRID(x) { x ## _TOP_LEFT, x ## _TOP, x ## _TOP_RIGHT, \ + x ## _LEFT, x ## _CENTER, x ## _RIGHT, \ + x ## _BOTTOM_LEFT, x ## _BOTTOM, x ## _BOTTOM_RIGHT, } + namespace views { // Painter, as the name implies, is responsible for painting in a particular @@ -44,14 +49,19 @@ class VIEWS_EXPORT Painter { size_t count); // Creates a painter that divides |image| into nine regions. The four corners - // are rendered at the size specified in insets (for example, the upper - // left corners is rendered at 0x0 with a size of - // insets.left()xinsets.right()). The four edges are stretched to fill the - // destination size. - // Ownership is passed to the caller. + // are rendered at the size specified in insets (eg. the upper-left corner is + // rendered at 0 x 0 with a size of insets.left() x insets.top()). The four + // edges are tiled and the center is stretched to fill the destination size. static Painter* CreateImagePainter(const gfx::ImageSkia& image, - const gfx::Insets& insets, - bool paint_center); + const gfx::Insets& insets); + + // Creates a painter that paints nine images as a scalable grid. The four + // corners are rendered in their full sizes (they are assumed to share widths + // by column and heights by row). The four edges are tiled and the center is + // stretched to fill the destination size. + // |image_ids| must contain nine image IDs specified in this order: Top-Left, + // Top, Top-Right, Left, Center, Right, Bottom-Left, Bottom, Bottom-Right. + static Painter* CreateImageGridPainter(const int image_ids[]); virtual ~Painter() {} diff --git a/ui/views/views.gyp b/ui/views/views.gyp index 6bfd9f5..5b84c3d 100644 --- a/ui/views/views.gyp +++ b/ui/views/views.gyp @@ -67,8 +67,6 @@ 'color_constants.cc', 'color_constants.h', 'context_menu_controller.h', - 'controls/button/border_images.cc', - 'controls/button/border_images.h', 'controls/button/button.cc', 'controls/button/button.h', 'controls/button/button_dropdown.cc', |