Skip to content

Commit

Permalink
Changes look for scrollbars on windows
Browse files Browse the repository at this point in the history
Additionally respects the size from the OS.

BUG=333499 332937
TEST=none
R=sadrul@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245886 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
sky@chromium.org committed Jan 20, 2014
1 parent 3510679 commit cd1fcd0
Show file tree
Hide file tree
Showing 19 changed files with 645 additions and 146 deletions.
3 changes: 2 additions & 1 deletion chrome/app/chrome_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ 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.
Expand All @@ -242,7 +244,6 @@ 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 ||
Expand Down
32 changes: 32 additions & 0 deletions ui/base/nine_image_painter_factory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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
29 changes: 29 additions & 0 deletions ui/base/nine_image_painter_factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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_
8 changes: 8 additions & 0 deletions ui/gfx/gfx.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@
'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',
Expand Down Expand Up @@ -403,6 +405,12 @@
],
},
}],
['use_aura==0', {
'sources!': [
'nine_image_painter.cc',
'nine_image_painter.h',
],
}],
['OS=="android" and use_aura==0', {
'sources!': [
'path.cc',
Expand Down
104 changes: 104 additions & 0 deletions ui/gfx/nine_image_painter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// 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
49 changes: 49 additions & 0 deletions ui/gfx/nine_image_painter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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_
2 changes: 2 additions & 0 deletions ui/native_theme/native_theme.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
'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',
Expand Down
11 changes: 6 additions & 5 deletions ui/native_theme/native_theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ class NATIVE_THEME_EXPORT NativeTheme {

// The state of the part.
enum State {
kDisabled,
kHovered,
kNormal,
kPressed,
kMaxState,
// IDs defined as specific values for use in arrays.
kDisabled = 0,
kHovered = 1,
kNormal = 2,
kPressed = 3,
kMaxState = 4,
};

// Each structure below holds extra information needed when painting a given
Expand Down
2 changes: 2 additions & 0 deletions ui/native_theme/native_theme_aura.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace ui {

#if !defined(OS_WIN)
// static
NativeTheme* NativeTheme::instance() {
return NativeThemeAura::instance();
Expand All @@ -27,6 +28,7 @@ NativeThemeAura* NativeThemeAura::instance() {
CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme, ());
return &s_native_theme;
}
#endif

NativeThemeAura::NativeThemeAura() {
// We don't draw scrollbar buttons.
Expand Down
2 changes: 1 addition & 1 deletion ui/native_theme/native_theme_aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class NATIVE_THEME_EXPORT NativeThemeAura : public FallbackTheme {
public:
static NativeThemeAura* instance();

private:
protected:
NativeThemeAura();
virtual ~NativeThemeAura();

Expand Down
Loading

0 comments on commit cd1fcd0

Please sign in to comment.