diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-20 19:34:57 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-20 19:34:57 +0000 |
commit | f9a4a3ab3a7e9c05c18e49b58e0d5dafffe0052c (patch) | |
tree | f69bd3460ef1940ea83e4a470de569f69ab6e947 | |
parent | 7f4c6d23f3b1726e5587f4e471561f8c3fc1020a (diff) | |
download | chromium_src-f9a4a3ab3a7e9c05c18e49b58e0d5dafffe0052c.zip chromium_src-f9a4a3ab3a7e9c05c18e49b58e0d5dafffe0052c.tar.gz chromium_src-f9a4a3ab3a7e9c05c18e49b58e0d5dafffe0052c.tar.bz2 |
Revert of Changes look for scrollbars on windows (https://codereview.chromium.org/137533012/)
Reason for revert:
Broke webkit_unit_tests:ScrollingCoordinatorChromiumTest.rtlIframe
Original issue's description:
> Changes look for scrollbars on windows
>
> Additionally respects the size from the OS.
>
> BUG=333499 332937
> TEST=none
> R=sadrul@chromium.org
>
> Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=245886
TBR=sadrul@chromium.org,jam@chromium.org,cpu@chromium.org,sky@chromium.org
NOTREECHECKS=true
NOTRY=true
BUG=333499 332937
Review URL: https://codereview.chromium.org/141123003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245938 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/chrome_main_delegate.cc | 3 | ||||
-rw-r--r-- | ui/base/nine_image_painter_factory.cc | 32 | ||||
-rw-r--r-- | ui/base/nine_image_painter_factory.h | 29 | ||||
-rw-r--r-- | ui/gfx/gfx.gyp | 8 | ||||
-rw-r--r-- | ui/gfx/nine_image_painter.cc | 104 | ||||
-rw-r--r-- | ui/gfx/nine_image_painter.h | 49 | ||||
-rw-r--r-- | ui/native_theme/native_theme.gyp | 2 | ||||
-rw-r--r-- | ui/native_theme/native_theme.h | 11 | ||||
-rw-r--r-- | ui/native_theme/native_theme_aura.cc | 2 | ||||
-rw-r--r-- | ui/native_theme/native_theme_aura.h | 2 | ||||
-rw-r--r-- | ui/native_theme/native_theme_aurawin.cc | 182 | ||||
-rw-r--r-- | ui/native_theme/native_theme_aurawin.h | 72 | ||||
-rw-r--r-- | ui/native_theme/native_theme_base.cc | 74 | ||||
-rw-r--r-- | ui/native_theme/native_theme_base.h | 16 | ||||
-rw-r--r-- | ui/native_theme/native_theme_win.cc | 11 | ||||
-rw-r--r-- | ui/resources/ui_resources.grd | 86 | ||||
-rw-r--r-- | ui/ui.gyp | 4 | ||||
-rw-r--r-- | ui/views/painter.cc | 98 | ||||
-rw-r--r-- | ui/views/painter.h | 6 |
19 files changed, 146 insertions, 645 deletions
diff --git a/chrome/app/chrome_main_delegate.cc b/chrome/app/chrome_main_delegate.cc index 2b69548..579874d 100644 --- a/chrome/app/chrome_main_delegate.cc +++ b/chrome/app/chrome_main_delegate.cc @@ -234,8 +234,6 @@ bool SubprocessNeedsResourceBundle(const std::string& process_type) { // Windows needs resources for the default/null plugin. // Mac needs them for the plugin process name. process_type == switches::kPluginProcess || - // Needed for scrollbar related images. - process_type == switches::kWorkerProcess || #endif #if defined(OS_POSIX) && !defined(OS_MACOSX) // The zygote process opens the resources for the renderers. @@ -244,6 +242,7 @@ bool SubprocessNeedsResourceBundle(const std::string& process_type) { #if defined(OS_MACOSX) // Mac needs them too for scrollbar related images and for sandbox // profiles. + process_type == switches::kWorkerProcess || process_type == switches::kNaClLoaderProcess || process_type == switches::kPpapiPluginProcess || process_type == switches::kPpapiBrokerProcess || diff --git a/ui/base/nine_image_painter_factory.cc b/ui/base/nine_image_painter_factory.cc deleted file mode 100644 index b22ba67..0000000 --- a/ui/base/nine_image_painter_factory.cc +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2014 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/base/nine_image_painter_factory.h" - -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/nine_image_painter.h" - -namespace ui { - -namespace { - -std::vector<gfx::ImageSkia> ImageIdsToImages(const int image_ids[]) { - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - std::vector<gfx::ImageSkia> images(9); - for (size_t i = 0; i < 9; ++i) { - if (image_ids[i] != 0) - images[i] = *rb.GetImageSkiaNamed(image_ids[i]); - } - return images; -} - -} // namespace - -scoped_ptr<gfx::NineImagePainter> CreateNineImagePainter( - const int image_ids[]) { - return scoped_ptr<gfx::NineImagePainter>( - new gfx::NineImagePainter(ImageIdsToImages(image_ids))); -} - -} // namespace ui diff --git a/ui/base/nine_image_painter_factory.h b/ui/base/nine_image_painter_factory.h deleted file mode 100644 index 51250dd..0000000 --- a/ui/base/nine_image_painter_factory.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2014 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_BASE_NINE_IMAGE_PAINTER_FACTORY_H_ -#define UI_BASE_NINE_IMAGE_PAINTER_FACTORY_H_ - -#include "base/memory/scoped_ptr.h" -#include "ui/base/ui_base_export.h" - -// 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 gfx { -class NineImagePainter; -} - -namespace ui { - -// Creates a NineImagePainter from an array of image ids. It's expected the -// array came from the IMAGE_GRID macro. -UI_BASE_EXPORT scoped_ptr<gfx::NineImagePainter> CreateNineImagePainter( - const int image_ids[]); - -} // namespace ui - -#endif // UI_BASE_NINE_IMAGE_PAINTER_FACTORY_H_ diff --git a/ui/gfx/gfx.gyp b/ui/gfx/gfx.gyp index a8ff4ed..66c384e 100644 --- a/ui/gfx/gfx.gyp +++ b/ui/gfx/gfx.gyp @@ -222,8 +222,6 @@ 'linux_font_delegate.h', 'mac/scoped_ns_disable_screen_updates.h', 'native_widget_types.h', - 'nine_image_painter.cc', - 'nine_image_painter.h', 'ozone/dri/dri_skbitmap.cc', 'ozone/dri/dri_skbitmap.h', 'ozone/dri/dri_surface.cc', @@ -405,12 +403,6 @@ ], }, }], - ['use_aura==0', { - 'sources!': [ - 'nine_image_painter.cc', - 'nine_image_painter.h', - ], - }], ['OS=="android" and use_aura==0', { 'sources!': [ 'path.cc', diff --git a/ui/gfx/nine_image_painter.cc b/ui/gfx/nine_image_painter.cc deleted file mode 100644 index d54dac9..0000000 --- a/ui/gfx/nine_image_painter.cc +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2014 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/gfx/nine_image_painter.h" - -#include "ui/gfx/canvas.h" -#include "ui/gfx/image/image_skia_operations.h" -#include "ui/gfx/insets.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/scoped_canvas.h" - -namespace gfx { - -NineImagePainter::NineImagePainter(const std::vector<ImageSkia>& images) { - DCHECK_EQ(arraysize(images_), images.size()); - for (size_t i = 0; i < arraysize(images_); ++i) - images_[i] = images[i]; -} - -NineImagePainter::NineImagePainter(const ImageSkia& image, - const 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] = ImageSkiaOperations::ExtractSubset(image, - Rect(x[i], y[j], x[i + 1] - x[i], y[j + 1] - y[j])); - } - } -} - -NineImagePainter::~NineImagePainter() { -} - -bool NineImagePainter::IsEmpty() const { - return images_[0].isNull(); -} - -Size NineImagePainter::GetMinimumSize() const { - return IsEmpty() ? Size() : Size( - images_[0].width() + images_[1].width() + images_[2].width(), - images_[0].height() + images_[3].height() + images_[6].height()); -} - -void NineImagePainter::Paint(Canvas* canvas, const Rect& bounds) { - if (IsEmpty()) - return; - - ScopedCanvas scoped_canvas(canvas); - canvas->Translate(bounds.OffsetFromOrigin()); - - // In case the corners and edges don't all have the same width/height, we draw - // the center first, and extend it out in all directions to the edges of the - // images with the smallest widths/heights. This way there will be no - // unpainted areas, though some corners or edges might overlap the center. - int w = bounds.width(); - int i0w = images_[0].width(); - int i2w = images_[2].width(); - int i3w = images_[3].width(); - int i5w = images_[5].width(); - int i6w = images_[6].width(); - int i8w = images_[8].width(); - int i4x = std::min(std::min(i0w, i3w), i6w); - int i4w = w - i4x - std::min(std::min(i2w, i5w), i8w); - int h = bounds.height(); - int i0h = images_[0].height(); - int i1h = images_[1].height(); - int i2h = images_[2].height(); - int i6h = images_[6].height(); - int i7h = images_[7].height(); - int i8h = images_[8].height(); - int i4y = std::min(std::min(i0h, i1h), i2h); - int i4h = h - i4y - std::min(std::min(i6h, i7h), i8h); - if (!images_[4].isNull()) - Fill(canvas, images_[4], i4x, i4y, i4w, i4h); - canvas->DrawImageInt(images_[0], 0, 0); - Fill(canvas, images_[1], i0w, 0, w - i0w - i2w, i1h); - canvas->DrawImageInt(images_[2], w - i2w, 0); - Fill(canvas, images_[3], 0, i0h, i3w, h - i0h - i6h); - Fill(canvas, images_[5], w - i5w, i2h, i5w, h - i2h - i8h); - canvas->DrawImageInt(images_[6], 0, h - i6h); - Fill(canvas, images_[7], i6w, h - i7h, w - i6w - i8w, i7h); - canvas->DrawImageInt(images_[8], w - i8w, h - i8h); -} - -// static -void NineImagePainter::Fill(Canvas* c, - const ImageSkia& i, - int x, - int y, - int w, - int h) { - c->DrawImageInt(i, 0, 0, i.width(), i.height(), x, y, w, h, false); -} - -} // namespace gfx diff --git a/ui/gfx/nine_image_painter.h b/ui/gfx/nine_image_painter.h deleted file mode 100644 index ce73fed..0000000 --- a/ui/gfx/nine_image_painter.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2014 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_GFX_NINE_IMAGE_PAINTER_H_ -#define UI_GFX_NINE_IMAGE_PAINTER_H_ - -#include "base/logging.h" -#include "ui/gfx/gfx_export.h" -#include "ui/gfx/image/image_skia.h" - -namespace gfx { - -class Canvas; -class Insets; -class Rect; - -class GFX_EXPORT NineImagePainter { - public: - explicit NineImagePainter(const std::vector<ImageSkia>& images); - NineImagePainter(const ImageSkia& image, const Insets& insets); - ~NineImagePainter(); - - bool IsEmpty() const; - Size GetMinimumSize() const; - void Paint(Canvas* canvas, const Rect& bounds); - - private: - // Stretches the given image over the specified canvas area. - static void Fill(Canvas* c, - const ImageSkia& i, - int x, - int y, - int w, - int h); - - // Images are numbered as depicted below. - // ____________________ - // |__i0__|__i1__|__i2__| - // |__i3__|__i4__|__i5__| - // |__i6__|__i7__|__i8__| - ImageSkia images_[9]; - - DISALLOW_COPY_AND_ASSIGN(NineImagePainter); -}; - -} // namespace gfx - -#endif // UI_GFX_NINE_IMAGE_PAINTER_H_ diff --git a/ui/native_theme/native_theme.gyp b/ui/native_theme/native_theme.gyp index f176468..4817c0b 100644 --- a/ui/native_theme/native_theme.gyp +++ b/ui/native_theme/native_theme.gyp @@ -33,8 +33,6 @@ 'native_theme_android.h', 'native_theme_aura.cc', 'native_theme_aura.h', - 'native_theme_aurawin.cc', - 'native_theme_aurawin.h', 'native_theme_base.cc', 'native_theme_base.h', 'native_theme_gtk.cc', diff --git a/ui/native_theme/native_theme.h b/ui/native_theme/native_theme.h index bc71120..9897414 100644 --- a/ui/native_theme/native_theme.h +++ b/ui/native_theme/native_theme.h @@ -78,12 +78,11 @@ class NATIVE_THEME_EXPORT NativeTheme { // The state of the part. enum State { - // IDs defined as specific values for use in arrays. - kDisabled = 0, - kHovered = 1, - kNormal = 2, - kPressed = 3, - kMaxState = 4, + kDisabled, + kHovered, + kNormal, + kPressed, + kMaxState, }; // Each structure below holds extra information needed when painting a given diff --git a/ui/native_theme/native_theme_aura.cc b/ui/native_theme/native_theme_aura.cc index 060418f..c4e8724 100644 --- a/ui/native_theme/native_theme_aura.cc +++ b/ui/native_theme/native_theme_aura.cc @@ -17,7 +17,6 @@ namespace ui { -#if !defined(OS_WIN) // static NativeTheme* NativeTheme::instance() { return NativeThemeAura::instance(); @@ -28,7 +27,6 @@ NativeThemeAura* NativeThemeAura::instance() { CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme, ()); return &s_native_theme; } -#endif NativeThemeAura::NativeThemeAura() { // We don't draw scrollbar buttons. diff --git a/ui/native_theme/native_theme_aura.h b/ui/native_theme/native_theme_aura.h index a31a97b..b3417b3 100644 --- a/ui/native_theme/native_theme_aura.h +++ b/ui/native_theme/native_theme_aura.h @@ -16,7 +16,7 @@ class NATIVE_THEME_EXPORT NativeThemeAura : public FallbackTheme { public: static NativeThemeAura* instance(); - protected: + private: NativeThemeAura(); virtual ~NativeThemeAura(); diff --git a/ui/native_theme/native_theme_aurawin.cc b/ui/native_theme/native_theme_aurawin.cc deleted file mode 100644 index 82aae3d..0000000 --- a/ui/native_theme/native_theme_aurawin.cc +++ /dev/null @@ -1,182 +0,0 @@ -// Copyright 2014 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/native_theme/native_theme_aurawin.h" - -#include "grit/ui_resources.h" -#include "third_party/skia/include/core/SkCanvas.h" -#include "ui/base/nine_image_painter_factory.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/nine_image_painter.h" -#include "ui/gfx/skia_util.h" -#include "ui/gfx/win/dpi.h" -#include "ui/native_theme/common_theme.h" -#include "ui/native_theme/native_theme_win.h" - -using gfx::NineImagePainter; - -#define EMPTY_IMAGE_GRID { 0, 0, 0, 0, 0, 0, 0, 0, 0 } - -namespace ui { - -namespace { - -const int kScrollbarThumbImages[NativeTheme::kMaxState][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] = { - 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 int kScrollbarTrackImages[9] = IMAGE_GRID(IDR_SCROLLBAR_BASE); - -} // namespace - -// static -NativeTheme* NativeTheme::instance() { - return NativeThemeAuraWin::instance(); -} - -// static -NativeThemeAura* NativeThemeAura::instance() { - return NativeThemeAuraWin::instance(); -} - -// static -NativeThemeAuraWin* NativeThemeAuraWin::instance() { - CR_DEFINE_STATIC_LOCAL(NativeThemeAuraWin, s_native_theme, ()); - return &s_native_theme; -} - -NativeThemeAuraWin::NativeThemeAuraWin() { - // Image 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); -} - -NativeThemeAuraWin::~NativeThemeAuraWin() { -} - -gfx::Size NativeThemeAuraWin::GetPartSize(Part part, - State state, - const ExtraParams& extra) const { - gfx::Size part_size = CommonThemeGetPartSize(part, state, extra); - if (!part_size.IsEmpty()) - return part_size; - - // We want aura on windows to use the same size for scrollbars as we would in - // the native theme. - switch (part) { - case kScrollbarDownArrow: - case kScrollbarLeftArrow: - case kScrollbarRightArrow: - case kScrollbarUpArrow: - case kScrollbarHorizontalThumb: - case kScrollbarVerticalThumb: - case kScrollbarHorizontalTrack: - case kScrollbarVerticalTrack: - return NativeThemeWin::instance()->GetPartSize(part, state, extra); - default: - break; - } - - return NativeThemeAura::GetPartSize(part, state, extra); -} - -void NativeThemeAuraWin::PaintArrowButton( - SkCanvas* gc, - const gfx::Rect& rect, - Part direction, - State state) const { - if (direction == kInnerSpinButton) { - NativeThemeAura::PaintArrowButton(gc, rect, direction, state); - return; - } - PaintPainter(GetOrCreatePainter( - kScrollbarArrowButtonImages, state, - scrollbar_arrow_button_painters_), - gc, rect); - - // The arrow is slightly offset to better balance with the thumb. - gfx::Rect arrow_rect(rect); - if (direction == kScrollbarDownArrow || direction == kScrollbarUpArrow) - arrow_rect.Offset(1, 0); - else - arrow_rect.Offset(0, 1); - - // Aura-win uses slightly different arrow colors. - SkColor arrow_color = GetArrowColor(state); - switch (state) { - case kHovered: - case kNormal: - arrow_color = SkColorSetRGB(0x50, 0x50, 0x50); - break; - case kPressed: - arrow_color = SK_ColorWHITE; - default: - break; - } - PaintArrow(gc, arrow_rect, direction, arrow_color); -} - -void NativeThemeAuraWin::PaintScrollbarTrack( - SkCanvas* sk_canvas, - Part part, - State state, - const ScrollbarTrackExtraParams& extra_params, - const gfx::Rect& rect) const { - if (!scrollbar_track_painter_) - scrollbar_track_painter_ = CreateNineImagePainter(kScrollbarTrackImages); - PaintPainter(scrollbar_track_painter_.get(), sk_canvas, rect); -} - -void NativeThemeAuraWin::PaintScrollbarThumb(SkCanvas* sk_canvas, - Part part, - State state, - const gfx::Rect& rect) const { - gfx::Rect thumb_rect(rect); - if (part == NativeTheme::kScrollbarVerticalThumb) - thumb_rect.Inset(3, 0, 1, 0); - else - thumb_rect.Inset(0, 3, 0, 1); - PaintPainter(GetOrCreatePainter( - kScrollbarThumbImages, state, scrollbar_thumb_painters_), - sk_canvas, thumb_rect); -} - -NineImagePainter* NativeThemeAuraWin::GetOrCreatePainter( - const int images[kMaxState][9], - State state, - scoped_ptr<NineImagePainter> painters[kMaxState]) const { - if (painters[state]) - return painters[state].get(); - if (images[state][0] == 0) { - // Must always provide normal state images. - DCHECK_NE(kNormal, state); - return GetOrCreatePainter(images, kNormal, painters); - } - painters[state] = CreateNineImagePainter(images[state]); - return painters[state].get(); -} - -void NativeThemeAuraWin::PaintPainter(NineImagePainter* painter, - SkCanvas* sk_canvas, - const gfx::Rect& rect) const { - DCHECK(painter); - scoped_ptr<gfx::Canvas> canvas(CreateCanvas(sk_canvas)); - painter->Paint(canvas.get(), rect); -} - -} // namespace ui diff --git a/ui/native_theme/native_theme_aurawin.h b/ui/native_theme/native_theme_aurawin.h deleted file mode 100644 index c1dadd0..0000000 --- a/ui/native_theme/native_theme_aurawin.h +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2014 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_NATIVE_THEME_NATIVE_THEME_AURAWIN_H_ -#define UI_NATIVE_THEME_NATIVE_THEME_AURAWIN_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ui/native_theme/native_theme_aura.h" - -namespace gfx { -class NineImagePainter; -} - -namespace ui { - -// Aura implementation of native theme support. -class NATIVE_THEME_EXPORT NativeThemeAuraWin : public NativeThemeAura { - public: - static NativeThemeAuraWin* instance(); - - private: - NativeThemeAuraWin(); - virtual ~NativeThemeAuraWin(); - - // Overridden from NativeThemeBase: - virtual gfx::Size GetPartSize(Part part, - State state, - const ExtraParams& extra) const OVERRIDE; - virtual void PaintArrowButton(SkCanvas* gc, - const gfx::Rect& rect, - Part direction, - State state) const OVERRIDE; - virtual void PaintScrollbarTrack( - SkCanvas* sk_canvas, - Part part, - State state, - const ScrollbarTrackExtraParams& extra_params, - const gfx::Rect& rect) const OVERRIDE; - virtual void PaintScrollbarThumb(SkCanvas* sk_canvas, - Part part, - State state, - const gfx::Rect& rect) const OVERRIDE; - - // Returns the NineImagePainter used to paint the specified state, creating if - // 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], - State state, - scoped_ptr<gfx::NineImagePainter> painters[kMaxState]) const; - - // Paints |painter| into the canvas using |rect|. - void PaintPainter(gfx::NineImagePainter* painter, - SkCanvas* sk_canvas, - const gfx::Rect& rect) const; - - mutable scoped_ptr<gfx::NineImagePainter> scrollbar_track_painter_; - - mutable scoped_ptr<gfx::NineImagePainter> - scrollbar_thumb_painters_[kMaxState]; - - mutable scoped_ptr<gfx::NineImagePainter> - scrollbar_arrow_button_painters_[kMaxState]; - - DISALLOW_COPY_AND_ASSIGN(NativeThemeAuraWin); -}; - -} // namespace ui - -#endif // UI_NATIVE_THEME_NATIVE_THEME_AURAWIN_H_ diff --git a/ui/native_theme/native_theme_base.cc b/ui/native_theme/native_theme_base.cc index cc0bacb..3b2bdd2 100644 --- a/ui/native_theme/native_theme_base.cc +++ b/ui/native_theme/native_theme_base.cc @@ -247,20 +247,18 @@ NativeThemeBase::NativeThemeBase() NativeThemeBase::~NativeThemeBase() { } -// static -scoped_ptr<gfx::Canvas> NativeThemeBase::CreateCanvas(SkCanvas* sk_canvas) { - // TODO(pkotwicz): Do something better and don't infer device - // scale factor from canvas scale. - SkMatrix m = sk_canvas->getTotalMatrix(); - float device_scale = static_cast<float>(SkScalarAbs(m.getScaleX())); - return scoped_ptr<gfx::Canvas>( - gfx::Canvas::CreateCanvasWithoutScaling(sk_canvas, device_scale)); -} - void NativeThemeBase::PaintArrowButton( SkCanvas* canvas, const gfx::Rect& rect, Part direction, State state) const { + int widthMiddle, lengthMiddle; SkPaint paint; + if (direction == kScrollbarUpArrow || direction == kScrollbarDownArrow) { + widthMiddle = rect.width() / 2 + 1; + lengthMiddle = rect.height() / 2 + 1; + } else { + lengthMiddle = rect.width() / 2 + 1; + widthMiddle = rect.height() / 2 + 1; + } // Calculate button color. SkScalar trackHSV[3]; @@ -335,24 +333,11 @@ void NativeThemeBase::PaintArrowButton( paint.setColor(OutlineColor(trackHSV, thumbHSV)); canvas->drawPath(outline, paint); - PaintArrow(canvas, rect, direction, GetArrowColor(state)); -} - -void NativeThemeBase::PaintArrow(SkCanvas* gc, - const gfx::Rect& rect, - Part direction, - SkColor color) const { - int width_middle, length_middle; - if (direction == kScrollbarUpArrow || direction == kScrollbarDownArrow) { - width_middle = rect.width() / 2 + 1; - length_middle = rect.height() / 2 + 1; - } else { - length_middle = rect.width() / 2 + 1; - width_middle = rect.height() / 2 + 1; - } + // If the button is disabled or read-only, the arrow is drawn with the + // outline color. + if (state != kDisabled) + paint.setColor(SK_ColorBLACK); - SkPaint paint; - paint.setColor(color); paint.setAntiAlias(false); paint.setStyle(SkPaint::kFill_Style); @@ -361,22 +346,22 @@ void NativeThemeBase::PaintArrow(SkCanvas* gc, // looking arrows without anti-aliasing. switch (direction) { case kScrollbarUpArrow: - path.moveTo(rect.x() + width_middle - 4, rect.y() + length_middle + 2); + path.moveTo(rect.x() + widthMiddle - 4, rect.y() + lengthMiddle + 2); path.rLineTo(7, 0); path.rLineTo(-4, -4); break; case kScrollbarDownArrow: - path.moveTo(rect.x() + width_middle - 4, rect.y() + length_middle - 3); + path.moveTo(rect.x() + widthMiddle - 4, rect.y() + lengthMiddle - 3); path.rLineTo(7, 0); path.rLineTo(-4, 4); break; case kScrollbarRightArrow: - path.moveTo(rect.x() + length_middle - 3, rect.y() + width_middle - 4); + path.moveTo(rect.x() + lengthMiddle - 3, rect.y() + widthMiddle - 4); path.rLineTo(0, 7); path.rLineTo(4, -4); break; case kScrollbarLeftArrow: - path.moveTo(rect.x() + length_middle + 1, rect.y() + width_middle - 5); + path.moveTo(rect.x() + lengthMiddle + 1, rect.y() + widthMiddle - 5); path.rLineTo(0, 9); path.rLineTo(-4, -4); break; @@ -385,7 +370,7 @@ void NativeThemeBase::PaintArrow(SkCanvas* gc, } path.close(); - gc->drawPath(path, paint); + canvas->drawPath(path, paint); } void NativeThemeBase::PaintScrollbarTrack(SkCanvas* canvas, @@ -1014,7 +999,12 @@ void NativeThemeBase::DrawImageInt( SkCanvas* sk_canvas, const gfx::ImageSkia& image, int src_x, int src_y, int src_w, int src_h, int dest_x, int dest_y, int dest_w, int dest_h) const { - scoped_ptr<gfx::Canvas> canvas(CreateCanvas(sk_canvas)); + // TODO(pkotwicz): Do something better and don't infer device + // scale factor from canvas scale. + SkMatrix m = sk_canvas->getTotalMatrix(); + float device_scale = static_cast<float>(SkScalarAbs(m.getScaleX())); + scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling( + sk_canvas, device_scale)); canvas->DrawImageInt(image, src_x, src_y, src_w, src_h, dest_x, dest_y, dest_w, dest_h, true); } @@ -1023,7 +1013,12 @@ void NativeThemeBase::DrawTiledImage(SkCanvas* sk_canvas, const gfx::ImageSkia& image, int src_x, int src_y, float tile_scale_x, float tile_scale_y, int dest_x, int dest_y, int w, int h) const { - scoped_ptr<gfx::Canvas> canvas(CreateCanvas(sk_canvas)); + // TODO(pkotwicz): Do something better and don't infer device + // scale factor from canvas scale. + SkMatrix m = sk_canvas->getTotalMatrix(); + float device_scale = static_cast<float>(SkScalarAbs(m.getScaleX())); + scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling( + sk_canvas, device_scale)); canvas->TileImageInt(image, src_x, src_y, tile_scale_x, tile_scale_y, dest_x, dest_y, w, h); } @@ -1038,17 +1033,6 @@ SkColor NativeThemeBase::SaturateAndBrighten(SkScalar* hsv, return SkHSVToColor(color); } -SkColor NativeThemeBase::GetArrowColor(State state) const { - if (state != kDisabled) - return SK_ColorBLACK; - - SkScalar track_hsv[3]; - SkColorToHSV(track_color_, track_hsv); - SkScalar thumb_hsv[3]; - SkColorToHSV(thumb_inactive_color_, thumb_hsv); - return OutlineColor(track_hsv, thumb_hsv); -} - void NativeThemeBase::DrawVertLine(SkCanvas* canvas, int x, int y1, diff --git a/ui/native_theme/native_theme_base.h b/ui/native_theme/native_theme_base.h index d8680862..9e314c3 100644 --- a/ui/native_theme/native_theme_base.h +++ b/ui/native_theme/native_theme_base.h @@ -7,12 +7,10 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" #include "skia/ext/platform_canvas.h" #include "ui/native_theme/native_theme.h" namespace gfx { -class Canvas; class ImageSkia; class Rect; class Size; @@ -37,9 +35,6 @@ class NATIVE_THEME_EXPORT NativeThemeBase : public NativeTheme { NativeThemeBase(); virtual ~NativeThemeBase(); - // Creates a gfx::Canvas wrapping an SkCanvas. - static scoped_ptr<gfx::Canvas> CreateCanvas(SkCanvas* sk_canvas); - // Draw the arrow. Used by scrollbar and inner spin button. virtual void PaintArrowButton( SkCanvas* gc, @@ -126,6 +121,7 @@ class NATIVE_THEME_EXPORT NativeThemeBase : public NativeTheme { const gfx::Rect& rect, const ProgressBarExtraParams& progress_bar) const; + protected: void set_scrollbar_button_length(unsigned int length) { scrollbar_button_length_ = length; } @@ -146,16 +142,6 @@ class NATIVE_THEME_EXPORT NativeThemeBase : public NativeTheme { SkColor SaturateAndBrighten(SkScalar* hsv, SkScalar saturate_amount, SkScalar brighten_amount) const; - - // Paints the arrow used on the scrollbar and spinner. - void PaintArrow(SkCanvas* canvas, - const gfx::Rect& rect, - Part direction, - SkColor color) const; - - // Returns the color used to draw the arrow. - SkColor GetArrowColor(State state) const; - private: void DrawVertLine(SkCanvas* canvas, int x, diff --git a/ui/native_theme/native_theme_win.cc b/ui/native_theme/native_theme_win.cc index bf21dcb..74b4f14 100644 --- a/ui/native_theme/native_theme_win.cc +++ b/ui/native_theme/native_theme_win.cc @@ -233,6 +233,7 @@ gfx::Size NativeThemeWin::GetPartSize(Part part, // The GetThemePartSize call below returns the default size without // accounting for user customization (crbug/218291). + SIZE size; switch (part) { case kScrollbarDownArrow: case kScrollbarLeftArrow: @@ -241,18 +242,14 @@ gfx::Size NativeThemeWin::GetPartSize(Part part, case kScrollbarHorizontalThumb: case kScrollbarVerticalThumb: case kScrollbarHorizontalTrack: - case kScrollbarVerticalTrack: { - int size = gfx::win::GetSystemMetricsInDIP(SM_CXVSCROLL); - if (size == 0) - size = 17; - return gfx::Size(size, size); - } + case kScrollbarVerticalTrack: + size.cx = size.cy = gfx::win::GetSystemMetricsInDIP(SM_CXVSCROLL); + return gfx::Size(size.cx, size.cy); } int part_id = GetWindowsPart(part, state, extra); int state_id = GetWindowsState(part, state, extra); - SIZE size; HDC hdc = GetDC(NULL); HRESULT hr = GetThemePartSize(GetThemeName(part), hdc, part_id, state_id, NULL, TS_TRUE, &size); diff --git a/ui/resources/ui_resources.grd b/ui/resources/ui_resources.grd index 026a478c..0eb10f1 100644 --- a/ui/resources/ui_resources.grd +++ b/ui/resources/ui_resources.grd @@ -384,18 +384,7 @@ <structure type="chrome_scaled_image" name="IDR_PROGRESS_BORDER_LEFT" file="linux/linux-progress-border-left.png" /> <structure type="chrome_scaled_image" name="IDR_PROGRESS_BORDER_RIGHT" file="linux/linux-progress-border-right.png" /> <structure type="chrome_scaled_image" name="IDR_PROGRESS_VALUE" file="linux/linux-progress-value.png" /> - </if> - <if expr="pp_ifdef('desktop_linux')"> - <structure type="chrome_scaled_image" name="IDR_RESTORE" file="linux/linux_restore.png" /> - <structure type="chrome_scaled_image" name="IDR_RESTORE_H" file="linux/linux_restore_hover.png" /> - <structure type="chrome_scaled_image" name="IDR_RESTORE_P" file="linux/linux_restore_pressed.png" /> - </if> - <if expr="not pp_ifdef('desktop_linux') and pp_ifdef('toolkit_views')"> - <structure type="chrome_scaled_image" name="IDR_RESTORE" file="restore.png" /> - <structure type="chrome_scaled_image" name="IDR_RESTORE_H" file="restore_hover.png" /> - <structure type="chrome_scaled_image" name="IDR_RESTORE_P" file="restore_pressed.png" /> - </if> - <if expr="pp_ifdef('use_aura') and not is_win"> + <structure type="chrome_scaled_image" name="IDR_SCROLL_BASE_HORIZONTAL_CENTER_H" file="cros/aura_scrollbar_base_horizontal_hover_center.png" /> <structure type="chrome_scaled_image" name="IDR_SCROLL_BASE_HORIZONTAL_LEFT_H" file="cros/aura_scrollbar_base_horizontal_hover_left.png" /> <structure type="chrome_scaled_image" name="IDR_SCROLL_BASE_HORIZONTAL_RIGHT_H" file="cros/aura_scrollbar_base_horizontal_hover_right.png" /> @@ -421,70 +410,15 @@ <structure type="chrome_scaled_image" name="IDR_SCROLL_THUMB_VERTICAL_TOP_H" file="cros/aura_scrollbar_thumb_vertical_hover_top.png" /> <structure type="chrome_scaled_image" name="IDR_SCROLL_THUMB_VERTICAL_TOP_P" file="cros/aura_scrollbar_thumb_vertical_pressed_top.png" /> </if> - <if expr="is_win"> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_HOVER_BOTTOM" file="win/aura_scrollbar_arrow_button_base_hover_bottom.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_HOVER_BOTTOM_LEFT" file="win/aura_scrollbar_arrow_button_base_hover_bottom_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_HOVER_BOTTOM_RIGHT" file="win/aura_scrollbar_arrow_button_base_hover_bottom_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_HOVER_CENTER" file="win/aura_scrollbar_arrow_button_base_hover_center.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_HOVER_LEFT" file="win/aura_scrollbar_arrow_button_base_hover_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_HOVER_RIGHT" file="win/aura_scrollbar_arrow_button_base_hover_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_HOVER_TOP" file="win/aura_scrollbar_arrow_button_base_hover_top.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_HOVER_TOP_LEFT" file="win/aura_scrollbar_arrow_button_base_hover_top_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_HOVER_TOP_RIGHT" file="win/aura_scrollbar_arrow_button_base_hover_top_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_NORMAL_BOTTOM" file="win/aura_scrollbar_arrow_button_base_normal_bottom.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_NORMAL_BOTTOM_LEFT" file="win/aura_scrollbar_arrow_button_base_normal_bottom_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_NORMAL_BOTTOM_RIGHT" file="win/aura_scrollbar_arrow_button_base_normal_bottom_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_NORMAL_CENTER" file="win/aura_scrollbar_arrow_button_base_normal_center.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_NORMAL_LEFT" file="win/aura_scrollbar_arrow_button_base_normal_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_NORMAL_RIGHT" file="win/aura_scrollbar_arrow_button_base_normal_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_NORMAL_TOP" file="win/aura_scrollbar_arrow_button_base_normal_top.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_NORMAL_TOP_LEFT" file="win/aura_scrollbar_arrow_button_base_normal_top_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_NORMAL_TOP_RIGHT" file="win/aura_scrollbar_arrow_button_base_normal_top_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_PRESSED_BOTTOM" file="win/aura_scrollbar_arrow_button_base_pressed_bottom.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_PRESSED_BOTTOM_LEFT" file="win/aura_scrollbar_arrow_button_base_pressed_bottom_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_PRESSED_BOTTOM_RIGHT" file="win/aura_scrollbar_arrow_button_base_pressed_bottom_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_PRESSED_CENTER" file="win/aura_scrollbar_arrow_button_base_pressed_center.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_PRESSED_LEFT" file="win/aura_scrollbar_arrow_button_base_pressed_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_PRESSED_RIGHT" file="win/aura_scrollbar_arrow_button_base_pressed_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_PRESSED_TOP" file="win/aura_scrollbar_arrow_button_base_pressed_top.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_PRESSED_TOP_LEFT" file="win/aura_scrollbar_arrow_button_base_pressed_top_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_ARROW_BUTTON_BASE_PRESSED_TOP_RIGHT" file="win/aura_scrollbar_arrow_button_base_pressed_top_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_BASE_BOTTOM" file="win/aura_scrollbar_base_bottom.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_BASE_BOTTOM_LEFT" file="win/aura_scrollbar_base_bottom_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_BASE_BOTTOM_RIGHT" file="win/aura_scrollbar_base_bottom_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_BASE_CENTER" file="win/aura_scrollbar_base_center.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_BASE_LEFT" file="win/aura_scrollbar_base_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_BASE_RIGHT" file="win/aura_scrollbar_base_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_BASE_TOP" file="win/aura_scrollbar_base_top.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_BASE_TOP_LEFT" file="win/aura_scrollbar_base_top_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_BASE_TOP_RIGHT" file="win/aura_scrollbar_base_top_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_HOVER_BOTTOM" file="win/aura_scrollbar_thumb_base_hover_bottom.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_HOVER_BOTTOM_LEFT" file="win/aura_scrollbar_thumb_base_hover_bottom_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_HOVER_BOTTOM_RIGHT" file="win/aura_scrollbar_thumb_base_hover_bottom_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_HOVER_CENTER" file="win/aura_scrollbar_thumb_base_hover_center.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_HOVER_LEFT" file="win/aura_scrollbar_thumb_base_hover_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_HOVER_RIGHT" file="win/aura_scrollbar_thumb_base_hover_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_HOVER_TOP" file="win/aura_scrollbar_thumb_base_hover_top.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_HOVER_TOP_LEFT" file="win/aura_scrollbar_thumb_base_hover_top_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_HOVER_TOP_RIGHT" file="win/aura_scrollbar_thumb_base_hover_top_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_NORMAL_BOTTOM" file="win/aura_scrollbar_thumb_base_normal_bottom.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_NORMAL_BOTTOM_LEFT" file="win/aura_scrollbar_thumb_base_normal_bottom_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_NORMAL_BOTTOM_RIGHT" file="win/aura_scrollbar_thumb_base_normal_bottom_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_NORMAL_CENTER" file="win/aura_scrollbar_thumb_base_normal_center.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_NORMAL_LEFT" file="win/aura_scrollbar_thumb_base_normal_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_NORMAL_RIGHT" file="win/aura_scrollbar_thumb_base_normal_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_NORMAL_TOP" file="win/aura_scrollbar_thumb_base_normal_top.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_NORMAL_TOP_LEFT" file="win/aura_scrollbar_thumb_base_normal_top_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_NORMAL_TOP_RIGHT" file="win/aura_scrollbar_thumb_base_normal_top_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_PRESSED_BOTTOM" file="win/aura_scrollbar_thumb_base_pressed_bottom.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_PRESSED_BOTTOM_LEFT" file="win/aura_scrollbar_thumb_base_pressed_bottom_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_PRESSED_BOTTOM_RIGHT" file="win/aura_scrollbar_thumb_base_pressed_bottom_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_PRESSED_CENTER" file="win/aura_scrollbar_thumb_base_pressed_center.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_PRESSED_LEFT" file="win/aura_scrollbar_thumb_base_pressed_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_PRESSED_RIGHT" file="win/aura_scrollbar_thumb_base_pressed_right.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_PRESSED_TOP" file="win/aura_scrollbar_thumb_base_pressed_top.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_PRESSED_TOP_LEFT" file="win/aura_scrollbar_thumb_base_pressed_top_left.png" /> - <structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_PRESSED_TOP_RIGHT" file="win/aura_scrollbar_thumb_base_pressed_top_right.png" /> + <if expr="pp_ifdef('desktop_linux')"> + <structure type="chrome_scaled_image" name="IDR_RESTORE" file="linux/linux_restore.png" /> + <structure type="chrome_scaled_image" name="IDR_RESTORE_H" file="linux/linux_restore_hover.png" /> + <structure type="chrome_scaled_image" name="IDR_RESTORE_P" file="linux/linux_restore_pressed.png" /> + </if> + <if expr="not pp_ifdef('desktop_linux') and pp_ifdef('toolkit_views')"> + <structure type="chrome_scaled_image" name="IDR_RESTORE" file="restore.png" /> + <structure type="chrome_scaled_image" name="IDR_RESTORE_H" file="restore_hover.png" /> + <structure type="chrome_scaled_image" name="IDR_RESTORE_P" file="restore_pressed.png" /> </if> <structure type="chrome_scaled_image" name="IDR_TEXTBUTTON_HOVER_BOTTOM" file="common/textbutton_hover_bottom.png" /> <structure type="chrome_scaled_image" name="IDR_TEXTBUTTON_HOVER_BOTTOM_LEFT" file="common/textbutton_hover_bottom_left.png" /> @@ -236,8 +236,6 @@ 'base/models/tree_model.h', 'base/models/tree_node_iterator.h', 'base/models/tree_node_model.h', - 'base/nine_image_painter_factory.cc', - 'base/nine_image_painter_factory.h', 'base/resource/data_pack.cc', 'base/resource/data_pack.h', 'base/resource/resource_bundle.cc', @@ -383,8 +381,6 @@ 'base/cursor/cursor_mac.mm', 'base/cursor/cursor_win.cc', 'base/cursor/cursor_x11.cc', - 'base/nine_image_painter_factory.cc', - 'base/nine_image_painter_factory.h', 'base/x/selection_owner.cc', 'base/x/selection_owner.h', 'base/x/selection_requestor.cc', diff --git a/ui/views/painter.cc b/ui/views/painter.cc index d445c15..b6a2e7d 100644 --- a/ui/views/painter.cc +++ b/ui/views/painter.cc @@ -13,7 +13,6 @@ #include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia_operations.h" #include "ui/gfx/insets.h" -#include "ui/gfx/nine_image_painter.h" #include "ui/gfx/point.h" #include "ui/gfx/rect.h" #include "ui/views/view.h" @@ -174,34 +173,117 @@ class VIEWS_EXPORT ImagePainter : public Painter { virtual ~ImagePainter(); + // Returns true if the images are empty. + bool IsEmpty() const; + // Painter: virtual gfx::Size GetMinimumSize() const OVERRIDE; virtual void Paint(gfx::Canvas* canvas, const gfx::Size& size) OVERRIDE; private: - scoped_ptr<gfx::NineImagePainter> nine_painter_; + // Stretches the given image over the specified canvas area. + static void Fill(gfx::Canvas* c, + const gfx::ImageSkia& i, + int x, + int y, + int w, + int h); + + // Images are numbered as depicted below. + // ____________________ + // |__i0__|__i1__|__i2__| + // |__i3__|__i4__|__i5__| + // |__i6__|__i7__|__i8__| + gfx::ImageSkia images_[9]; DISALLOW_COPY_AND_ASSIGN(ImagePainter); }; -ImagePainter::ImagePainter(const int image_ids[]) - : nine_painter_(ui::CreateNineImagePainter(image_ids)) { +ImagePainter::ImagePainter(const int image_ids[]) { + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); + for (size_t i = 0; i < 9; ++i) + if (image_ids[i] != 0) + images_[i] = *rb.GetImageSkiaNamed(image_ids[i]); } ImagePainter::ImagePainter(const gfx::ImageSkia& image, - const gfx::Insets& insets) - : nine_painter_(new gfx::NineImagePainter(image, insets)) { + 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(); +} + gfx::Size ImagePainter::GetMinimumSize() const { - return nine_painter_->GetMinimumSize(); + return IsEmpty() ? gfx::Size() : gfx::Size( + images_[0].width() + images_[1].width() + images_[2].width(), + images_[0].height() + images_[3].height() + images_[6].height()); } void ImagePainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { - nine_painter_->Paint(canvas, gfx::Rect(size)); + if (IsEmpty()) + return; + + // In case the corners and edges don't all have the same width/height, we draw + // the center first, and extend it out in all directions to the edges of the + // images with the smallest widths/heights. This way there will be no + // unpainted areas, though some corners or edges might overlap the center. + int w = size.width(); + int i0w = images_[0].width(); + int i2w = images_[2].width(); + int i3w = images_[3].width(); + int i5w = images_[5].width(); + int i6w = images_[6].width(); + int i8w = images_[8].width(); + int i4x = std::min(std::min(i0w, i3w), i6w); + int i4w = w - i4x - std::min(std::min(i2w, i5w), i8w); + int h = size.height(); + int i0h = images_[0].height(); + int i1h = images_[1].height(); + int i2h = images_[2].height(); + int i6h = images_[6].height(); + int i7h = images_[7].height(); + int i8h = images_[8].height(); + int i4y = std::min(std::min(i0h, i1h), i2h); + int i4h = h - i4y - std::min(std::min(i6h, i7h), i8h); + if (!images_[4].isNull()) + Fill(canvas, images_[4], i4x, i4y, i4w, i4h); + canvas->DrawImageInt(images_[0], 0, 0); + Fill(canvas, images_[1], i0w, 0, w - i0w - i2w, i1h); + canvas->DrawImageInt(images_[2], w - i2w, 0); + Fill(canvas, images_[3], 0, i0h, i3w, h - i0h - i6h); + Fill(canvas, images_[5], w - i5w, i2h, i5w, h - i2h - i8h); + canvas->DrawImageInt(images_[6], 0, h - i6h); + Fill(canvas, images_[7], i6w, h - i7h, w - i6w - i8w, i7h); + canvas->DrawImageInt(images_[8], w - i8w, h - i8h); +} + +// static +void ImagePainter::Fill(gfx::Canvas* c, + const gfx::ImageSkia& i, + int x, + int y, + int w, + int h) { + c->DrawImageInt(i, 0, 0, i.width(), i.height(), x, y, w, h, false); } } // namespace diff --git a/ui/views/painter.h b/ui/views/painter.h index 6efd281..3799e91 100644 --- a/ui/views/painter.h +++ b/ui/views/painter.h @@ -9,7 +9,6 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "third_party/skia/include/core/SkColor.h" -#include "ui/base/nine_image_painter_factory.h" #include "ui/views/views_export.h" namespace gfx { @@ -20,6 +19,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 { class View; |