Commit a12f7fbe authored by xiyuan@chromium.org's avatar xiyuan@chromium.org

Move more web widgets painting from webkit to chrome.

- Move linux web widgets painting code from webkit;
- Move dependent resources from webkit_resources into gfx_resources and
  follow the pattern in net package to add resource loading support to
  gfx package;
- Update ChromeOS theme engine to follow mocks in chromium-os:9256.

BUG=chromium-os:9256
TEST=Verify default web widgets has desired look on ChromeOS.

Review URL: http://codereview.chromium.org/6254004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71969 0039d316-1c4b-4281-b951-d872f2087c98
parent f224f15f
...@@ -76,6 +76,7 @@ ...@@ -76,6 +76,7 @@
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/env_vars.h" #include "chrome/common/env_vars.h"
#include "chrome/common/gfx_resource_provider.h"
#include "chrome/common/hi_res_timer_manager.h" #include "chrome/common/hi_res_timer_manager.h"
#include "chrome/common/json_pref_store.h" #include "chrome/common/json_pref_store.h"
#include "chrome/common/jstemplate_builder.h" #include "chrome/common/jstemplate_builder.h"
...@@ -85,6 +86,7 @@ ...@@ -85,6 +86,7 @@
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/result_codes.h" #include "chrome/common/result_codes.h"
#include "chrome/installer/util/google_update_settings.h" #include "chrome/installer/util/google_update_settings.h"
#include "gfx/gfx_module.h"
#include "grit/app_locale_settings.h" #include "grit/app_locale_settings.h"
#include "grit/chromium_strings.h" #include "grit/chromium_strings.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
...@@ -1507,8 +1509,9 @@ int BrowserMain(const MainFunctionParams& parameters) { ...@@ -1507,8 +1509,9 @@ int BrowserMain(const MainFunctionParams& parameters) {
#endif #endif
#endif #endif
// Configure the network module so it has access to resources. // Configure modules that need access to resources.
net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider); net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider);
gfx::GfxModule::SetResourceProvider(chrome::GfxResourceProvider);
// Register our global network handler for chrome:// and // Register our global network handler for chrome:// and
// chrome-extension:// URLs. // chrome-extension:// URLs.
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
#include "chrome/browser/chromeos/native_theme_chromeos.h" #include "chrome/browser/chromeos/native_theme_chromeos.h"
#include <limits>
#include "app/resource_bundle.h" #include "app/resource_bundle.h"
#include "base/logging.h" #include "base/logging.h"
#include "gfx/insets.h" #include "gfx/insets.h"
...@@ -15,67 +13,6 @@ ...@@ -15,67 +13,6 @@
#include "grit/theme_resources.h" #include "grit/theme_resources.h"
#include "third_party/skia/include/core/SkShader.h" #include "third_party/skia/include/core/SkShader.h"
namespace {
bool IntersectsClipRectInt(
skia::PlatformCanvas* canvas, int x, int y, int w, int h) {
SkRect clip;
return canvas->getClipBounds(&clip) &&
clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w),
SkIntToScalar(y + h));
}
void DrawBitmapInt(
skia::PlatformCanvas* canvas, const SkBitmap& bitmap,
int src_x, int src_y, int src_w, int src_h,
int dest_x, int dest_y, int dest_w, int dest_h) {
DLOG_ASSERT(src_x + src_w < std::numeric_limits<int16_t>::max() &&
src_y + src_h < std::numeric_limits<int16_t>::max());
if (src_w <= 0 || src_h <= 0 || dest_w <= 0 || dest_h <= 0) {
NOTREACHED() << "Attempting to draw bitmap to/from an empty rect!";
return;
}
if (!IntersectsClipRectInt(canvas, dest_x, dest_y, dest_w, dest_h))
return;
SkRect dest_rect = { SkIntToScalar(dest_x),
SkIntToScalar(dest_y),
SkIntToScalar(dest_x + dest_w),
SkIntToScalar(dest_y + dest_h) };
if (src_w == dest_w && src_h == dest_h) {
// Workaround for apparent bug in Skia that causes image to occasionally
// shift.
SkIRect src_rect = { src_x, src_y, src_x + src_w, src_y + src_h };
canvas->drawBitmapRect(bitmap, &src_rect, dest_rect);
return;
}
// Make a bitmap shader that contains the bitmap we want to draw. This is
// basically what SkCanvas.drawBitmap does internally, but it gives us
// more control over quality and will use the mipmap in the source image if
// it has one, whereas drawBitmap won't.
SkShader* shader = SkShader::CreateBitmapShader(bitmap,
SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode);
SkMatrix shader_scale;
shader_scale.setScale(SkFloatToScalar(static_cast<float>(dest_w) / src_w),
SkFloatToScalar(static_cast<float>(dest_h) / src_h));
shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y));
shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y));
shader->setLocalMatrix(shader_scale);
// The rect will be filled by the bitmap.
SkPaint p;
p.setFilterBitmap(true);
p.setShader(shader);
shader->unref();
canvas->drawRect(dest_rect, p);
}
}
/* static */ /* static */
gfx::NativeThemeLinux* gfx::NativeThemeLinux::instance() { gfx::NativeThemeLinux* gfx::NativeThemeLinux::instance() {
// The global NativeThemeChromeos instance. // The global NativeThemeChromeos instance.
...@@ -89,7 +26,7 @@ NativeThemeChromeos::NativeThemeChromeos() { ...@@ -89,7 +26,7 @@ NativeThemeChromeos::NativeThemeChromeos() {
NativeThemeChromeos::~NativeThemeChromeos() { NativeThemeChromeos::~NativeThemeChromeos() {
} }
gfx::Size NativeThemeChromeos::GetSize(Part part) const { gfx::Size NativeThemeChromeos::GetPartSize(Part part) const {
ResourceBundle& rb = ResourceBundle::GetSharedInstance(); ResourceBundle& rb = ResourceBundle::GetSharedInstance();
int scrollbar_width = rb.GetBitmapNamed(IDR_SCROLL_BACKGROUND)->width(); int scrollbar_width = rb.GetBitmapNamed(IDR_SCROLL_BACKGROUND)->width();
int width = 0, height = 0; int width = 0, height = 0;
...@@ -124,11 +61,13 @@ gfx::Size NativeThemeChromeos::GetSize(Part part) const { ...@@ -124,11 +61,13 @@ gfx::Size NativeThemeChromeos::GetSize(Part part) const {
width = scrollbar_width; width = scrollbar_width;
height = scrollbar_width; height = scrollbar_width;
break; break;
default:
return NativeThemeLinux::GetPartSize(part);
} }
return gfx::Size(width, height); return gfx::Size(width, height);
} }
void NativeThemeChromeos::PaintTrack(skia::PlatformCanvas* canvas, void NativeThemeChromeos::PaintScrollbarTrack(skia::PlatformCanvas* canvas,
Part part, State state, Part part, State state,
const ScrollbarTrackExtraParams& extra_params, const gfx::Rect& rect) { const ScrollbarTrackExtraParams& extra_params, const gfx::Rect& rect) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance(); ResourceBundle& rb = ResourceBundle::GetSharedInstance();
...@@ -174,11 +113,11 @@ void NativeThemeChromeos::PaintTrack(skia::PlatformCanvas* canvas, ...@@ -174,11 +113,11 @@ void NativeThemeChromeos::PaintTrack(skia::PlatformCanvas* canvas,
} }
} }
void NativeThemeChromeos::PaintThumb(skia::PlatformCanvas* canvas, void NativeThemeChromeos::PaintScrollbarThumb(skia::PlatformCanvas* canvas,
Part part, State state, const gfx::Rect& rect) { Part part, State state, const gfx::Rect& rect) {
ResourceBundle& rb = ResourceBundle::GetSharedInstance(); ResourceBundle& rb = ResourceBundle::GetSharedInstance();
int resource_id = IDR_SCROLL_THUMB; int resource_id = IDR_SCROLL_THUMB;
if (state == kHover) if (state == kHovered)
resource_id++; resource_id++;
else if (state == kPressed) else if (state == kPressed)
resource_id += 2; resource_id += 2;
...@@ -225,7 +164,7 @@ void NativeThemeChromeos::PaintArrowButton(skia::PlatformCanvas* canvas, ...@@ -225,7 +164,7 @@ void NativeThemeChromeos::PaintArrowButton(skia::PlatformCanvas* canvas,
int resource_id = int resource_id =
(part == kScrollbarUpArrow || part == kScrollbarLeftArrow) ? (part == kScrollbarUpArrow || part == kScrollbarLeftArrow) ?
IDR_SCROLL_ARROW_UP : IDR_SCROLL_ARROW_DOWN; IDR_SCROLL_ARROW_UP : IDR_SCROLL_ARROW_DOWN;
if (state == kHover) if (state == kHovered)
resource_id++; resource_id++;
else if (state == kPressed) else if (state == kPressed)
resource_id += 2; resource_id += 2;
...@@ -255,4 +194,3 @@ SkBitmap* NativeThemeChromeos::GetHorizontalBitmapNamed(int resource_id) { ...@@ -255,4 +194,3 @@ SkBitmap* NativeThemeChromeos::GetHorizontalBitmapNamed(int resource_id) {
} }
return NULL; return NULL;
} }
...@@ -17,14 +17,14 @@ class NativeThemeChromeos : public gfx::NativeThemeLinux { ...@@ -17,14 +17,14 @@ class NativeThemeChromeos : public gfx::NativeThemeLinux {
virtual ~NativeThemeChromeos(); virtual ~NativeThemeChromeos();
// Scrollbar painting overrides // Scrollbar painting overrides
virtual gfx::Size GetSize(Part part) const; virtual gfx::Size GetPartSize(Part part) const;
virtual void PaintTrack(skia::PlatformCanvas* canvas, virtual void PaintScrollbarTrack(skia::PlatformCanvas* canvas,
Part part, State state, Part part, State state,
const ScrollbarTrackExtraParams& extra_params, const ScrollbarTrackExtraParams& extra_params,
const gfx::Rect& rect); const gfx::Rect& rect);
virtual void PaintArrowButton(skia::PlatformCanvas* canvas, virtual void PaintArrowButton(skia::PlatformCanvas* canvas,
const gfx::Rect& rect, Part direction, State state); const gfx::Rect& rect, Part direction, State state);
virtual void PaintThumb(skia::PlatformCanvas* canvas, virtual void PaintScrollbarThumb(skia::PlatformCanvas* canvas,
Part part, State state, const gfx::Rect& rect); Part part, State state, const gfx::Rect& rect);
SkBitmap* GetHorizontalBitmapNamed(int resource_id); SkBitmap* GetHorizontalBitmapNamed(int resource_id);
......
...@@ -31,7 +31,7 @@ void UpdateFromSystemSettings(RendererPreferences* prefs, Profile* profile) { ...@@ -31,7 +31,7 @@ void UpdateFromSystemSettings(RendererPreferences* prefs, Profile* profile) {
prefs->inactive_selection_fg_color = prefs->inactive_selection_fg_color =
provider->get_inactive_selection_fg_color(); provider->get_inactive_selection_fg_color();
#else #else
prefs->focus_ring_color = SkColorSetARGB(255, 229, 151, 0); prefs->focus_ring_color = SkColorSetRGB(0x50, 0x7A, 0xD5);
prefs->active_selection_bg_color = SkColorSetRGB(0xDC, 0xE4, 0xFA); prefs->active_selection_bg_color = SkColorSetRGB(0xDC, 0xE4, 0xFA);
prefs->active_selection_fg_color = SK_ColorBLACK; prefs->active_selection_fg_color = SK_ColorBLACK;
prefs->inactive_selection_bg_color = SkColorSetRGB(0xF7, 0xF7, 0xF7); prefs->inactive_selection_bg_color = SkColorSetRGB(0xF7, 0xF7, 0xF7);
......
...@@ -1833,6 +1833,7 @@ ...@@ -1833,6 +1833,7 @@
'<(grit_out_dir)/renderer_resources.pak', '<(grit_out_dir)/renderer_resources.pak',
'<(grit_out_dir)/theme_resources.pak', '<(grit_out_dir)/theme_resources.pak',
'<(SHARED_INTERMEDIATE_DIR)/app/app_resources/app_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/app/app_resources/app_resources.pak',
'<(SHARED_INTERMEDIATE_DIR)/gfx/gfx_resources.pak',
'<(SHARED_INTERMEDIATE_DIR)/net/net_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/net/net_resources.pak',
'<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_chromium_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_chromium_resources.pak',
'<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_resources.pak',
......
...@@ -77,6 +77,8 @@ ...@@ -77,6 +77,8 @@
'common/font_config_ipc_linux.h', 'common/font_config_ipc_linux.h',
'common/geoposition.cc', 'common/geoposition.cc',
'common/geoposition.h', 'common/geoposition.h',
'common/gfx_resource_provider.cc',
'common/gfx_resource_provider.h',
'common/gpu_create_command_buffer_config.cc', 'common/gpu_create_command_buffer_config.cc',
'common/gpu_create_command_buffer_config.h', 'common/gpu_create_command_buffer_config.h',
'common/gpu_feature_flags.cc', 'common/gpu_feature_flags.cc',
......
// Copyright (c) 2011 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 "chrome/common/gfx_resource_provider.h"
#include "app/resource_bundle.h"
#include "base/string_piece.h"
namespace chrome {
base::StringPiece GfxResourceProvider(int key) {
return ResourceBundle::GetSharedInstance().GetRawDataResource(key);
}
} // namespace chrome
// Copyright (c) 2011 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 CHROME_COMMON_GFX_RESOURCE_PROVIDER_H_
#define CHROME_COMMON_GFX_RESOURCE_PROVIDER_H_
#pragma once
namespace base {
class StringPiece;
}
namespace chrome {
// This is called indirectly by the gfx theme code to access resources.
base::StringPiece GfxResourceProvider(int key);
} // namespace chrome
#endif // CHROME_COMMON_GFX_RESOURCE_PROVIDER_H_
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_counters.h" #include "chrome/common/chrome_counters.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/gfx_resource_provider.h"
#include "chrome/common/hi_res_timer_manager.h" #include "chrome/common/hi_res_timer_manager.h"
#include "chrome/common/logging_chrome.h" #include "chrome/common/logging_chrome.h"
#include "chrome/common/main_function_params.h" #include "chrome/common/main_function_params.h"
...@@ -29,6 +30,7 @@ ...@@ -29,6 +30,7 @@
#include "chrome/renderer/renderer_main_platform_delegate.h" #include "chrome/renderer/renderer_main_platform_delegate.h"
#include "chrome/renderer/render_process_impl.h" #include "chrome/renderer/render_process_impl.h"
#include "chrome/renderer/render_thread.h" #include "chrome/renderer/render_thread.h"
#include "gfx/gfx_module.h"
#include "grit/generated_resources.h" #include "grit/generated_resources.h"
#include "net/base/net_module.h" #include "net/base/net_module.h"
#include "ui/base/system_monitor/system_monitor.h" #include "ui/base/system_monitor/system_monitor.h"
...@@ -213,8 +215,9 @@ int RendererMain(const MainFunctionParams& parameters) { ...@@ -213,8 +215,9 @@ int RendererMain(const MainFunctionParams& parameters) {
InitCrashReporter(); InitCrashReporter();
#endif #endif
// Configure the network module so it has access to resources. // Configure modules that need access to resources.
net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider); net::NetModule::SetResourceProvider(chrome_common_net::NetResourceProvider);
gfx::GfxModule::SetResourceProvider(chrome::GfxResourceProvider);
// This function allows pausing execution using the --renderer-startup-dialog // This function allows pausing execution using the --renderer-startup-dialog
// flag allowing us to attach a debugger. // flag allowing us to attach a debugger.
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
'chromium_code': 1, 'chromium_code': 1,
'grit_info_cmd': ['python', '../tools/grit/grit_info.py', 'grit_info_cmd': ['python', '../tools/grit/grit_info.py',
'<@(grit_defines)'], '<@(grit_defines)'],
'grit_cmd': ['python', '../tools/grit/grit.py'], 'grit_cmd': ['python', '../tools/grit/grit.py'],
'grit_out_dir': '<(SHARED_INTERMEDIATE_DIR)/gfx', 'grit_out_dir': '<(SHARED_INTERMEDIATE_DIR)/gfx',
}, },
'targets': [ 'targets': [
...@@ -110,6 +110,8 @@ ...@@ -110,6 +110,8 @@
'font.cc', 'font.cc',
'gfx_paths.cc', 'gfx_paths.cc',
'gfx_paths.h', 'gfx_paths.h',
'gfx_module.cc',
'gfx_module.h',
'insets.cc', 'insets.cc',
'insets.h', 'insets.h',
'native_widget_types.h', 'native_widget_types.h',
...@@ -158,7 +160,7 @@ ...@@ -158,7 +160,7 @@
'include_dirs': [ 'include_dirs': [
'..', '..',
'<(DEPTH)/third_party/wtl/include', '<(DEPTH)/third_party/wtl/include',
], ],
}], }],
['OS=="linux" or OS=="freebsd" or OS=="openbsd"', { ['OS=="linux" or OS=="freebsd" or OS=="openbsd"', {
'dependencies': [ 'dependencies': [
...@@ -218,7 +220,7 @@ ...@@ -218,7 +220,7 @@
}], }],
], ],
}, },
], ],
} }
......
// Copyright (c) 2011 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 "gfx/gfx_module.h"
namespace gfx {
static GfxModule::ResourceProvider resource_provider = NULL;
// static
void GfxModule::SetResourceProvider(ResourceProvider func) {
resource_provider = func;
}
// static
base::StringPiece GfxModule::GetResource(int key) {
return resource_provider ? resource_provider(key) : base::StringPiece();
}
} // namespace gfx
// Copyright (c) 2011 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 GFX_MODULE_H_
#define GFX_MODULE_H_
#pragma once
#include "base/basictypes.h"
#include "base/string_piece.h"
namespace gfx {
// Defines global initializers and associated methods for the gfx module.
// See net/base/net_module.h for more details.
class GfxModule {
public:
typedef base::StringPiece (*ResourceProvider)(int key);
// Set the function to call when the gfx module needs resources
static void SetResourceProvider(ResourceProvider func);
// Call the resource provider (if one exists) to get the specified resource.
// Returns an empty string if the resource does not exist or if there is no
// resource provider.
static base::StringPiece GetResource(int key);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(GfxModule);
};
} // namespace gfx
#endif // GFX_MODULE_H_
...@@ -11,7 +11,27 @@ ...@@ -11,7 +11,27 @@
</outputs> </outputs>
<release seq="1"> <release seq="1">
<includes> <includes>
<include name="IDR_BITMAP_BRUSH_IMAGE" file="bitmap_brush_image.png" type="BINDATA" /> <if expr="os.find('win') != -1">
<!-- IDR_BITMAP_BRUSH_IMAGE is for canvas_direct2d_unittest on win -->
<include name="IDR_BITMAP_BRUSH_IMAGE" file="resources\bitmap_brush_image.png" type="BINDATA" />
</if>
<if expr="os == 'linux2' or os.find('bsd') != -1 or os == 'sunos5'">
<include name="IDR_LINUX_CHECKBOX_DISABLED_INDETERMINATE" file="resources\linux-checkbox-disabled-indeterminate.png" type="BINDATA" />
<include name="IDR_LINUX_CHECKBOX_DISABLED_OFF" file="resources\linux-checkbox-disabled-off.png" type="BINDATA" />
<include name="IDR_LINUX_CHECKBOX_DISABLED_ON" file="resources\linux-checkbox-disabled-on.png" type="BINDATA" />
<include name="IDR_LINUX_CHECKBOX_INDETERMINATE" file="resources\linux-checkbox-indeterminate.png" type="BINDATA" />
<include name="IDR_LINUX_CHECKBOX_OFF" file="resources\linux-checkbox-off.png" type="BINDATA" />
<include name="IDR_LINUX_CHECKBOX_ON" file="resources\linux-checkbox-on.png" type="BINDATA" />
<include name="IDR_LINUX_RADIO_DISABLED_OFF" file="resources\linux-radio-disabled-off.png" type="BINDATA" />
<include name="IDR_LINUX_RADIO_DISABLED_ON" file="resources\linux-radio-disabled-on.png" type="BINDATA" />
<include name="IDR_LINUX_RADIO_OFF" file="resources\linux-radio-off.png" type="BINDATA" />
<include name="IDR_LINUX_RADIO_ON" file="resources\linux-radio-on.png" type="BINDATA" />
<include name="IDR_PROGRESS_BAR" file="resources\linux-progress-bar.png" type="BINDATA" />
<include name="IDR_PROGRESS_BORDER_LEFT" file="resources\linux-progress-border-left.png" type="BINDATA" />
<include name="IDR_PROGRESS_BORDER_RIGHT" file="resources\linux-progress-border-right.png" type="BINDATA" />
<include name="IDR_PROGRESS_VALUE" file="resources\linux-progress-value.png" type="BINDATA" />
</if>
</includes> </includes>
</release> </release>
</grit> </grit>
......
This diff is collapsed.
...@@ -28,13 +28,22 @@ class NativeThemeLinux { ...@@ -28,13 +28,22 @@ class NativeThemeLinux {
kScrollbarHorizontalThumb, kScrollbarHorizontalThumb,
kScrollbarVerticalThumb, kScrollbarVerticalThumb,
kScrollbarHorizontalTrack, kScrollbarHorizontalTrack,
kScrollbarVerticalTrack kScrollbarVerticalTrack,
kCheckbox,
kRadio,
kPushButton,
kTextField,
kMenuList,
kSliderTrack,
kSliderThumb,
kInnerSpinButton,
kProgressBar,
}; };
// The state of the part. // The state of the part.
enum State { enum State {
kDisabled, kDisabled,
kHover, kHovered,
kNormal, kNormal,
kPressed, kPressed,
}; };
...@@ -47,15 +56,58 @@ class NativeThemeLinux { ...@@ -47,15 +56,58 @@ class NativeThemeLinux {
int track_height; int track_height;
}; };
struct ButtonExtraParams {
bool checked;
bool indeterminate; // Whether the button state is indeterminate.
bool is_default; // Whether the button is default button.
SkColor background_color;
};
struct TextFieldExtraParams {
bool is_text_area;
bool is_listbox;
SkColor background_color;
};
struct MenuListExtraParams {
int arrow_x;
int arrow_y;
SkColor background_color;
};
struct SliderExtraParams {
bool vertical;
bool in_drag;
};
struct InnerSpinButtonExtraParams {
bool spin_up;
bool read_only;
};
struct ProgressBarExtraParams {
bool determinate;
int value_rect_x;
int value_rect_y;
int value_rect_width;
int value_rect_height;
};
union ExtraParams { union ExtraParams {
ScrollbarTrackExtraParams scrollbar_track; ScrollbarTrackExtraParams scrollbar_track;
ButtonExtraParams button;
MenuListExtraParams menu_list;
SliderExtraParams slider;
TextFieldExtraParams text_field;
InnerSpinButtonExtraParams inner_spin;
ProgressBarExtraParams progress_bar;
}; };
// Gets our singleton instance. // Gets our singleton instance.
static NativeThemeLinux* instance(); static NativeThemeLinux* instance();
// Return the size of the part. // Return the size of the part.
virtual gfx::Size GetSize(Part part) const; virtual gfx::Size GetPartSize(Part part) const;
// Paint the part to the canvas. // Paint the part to the canvas.
virtual void Paint(skia::PlatformCanvas* canvas, virtual void Paint(skia::PlatformCanvas* canvas,
Part part, Part part,
...@@ -71,23 +123,87 @@ class NativeThemeLinux { ...@@ -71,23 +123,87 @@ class NativeThemeLinux {
NativeThemeLinux(); NativeThemeLinux();
virtual ~NativeThemeLinux(); virtual ~NativeThemeLinux();
// Draw the arrow. // Draw the arrow. Used by scrollbar and inner spin button.
virtual void PaintArrowButton( virtual void PaintArrowButton(
skia::PlatformCanvas* gc, skia::PlatformCanvas* gc,
const gfx::Rect& rect, const gfx::Rect& rect,
Part direction, Part direction,
State state); State state);
// Paint the track. Done before the thumb so that it can contain alpha. // Paint the scrollbar track. Done before the thumb so that it can contain
virtual void PaintTrack(skia::PlatformCanvas* canvas, // alpha.
Part part, virtual void PaintScrollbarTrack(skia::PlatformCanvas* canvas,
State state, Part part,
const ScrollbarTrackExtraParams& extra_params, State state,
const gfx::Rect& rect); const ScrollbarTrackExtraParams& extra_params,
// Draw the thumb over the track. const gfx::Rect& rect);
virtual void PaintThumb(skia::PlatformCanvas* canvas, // Draw the scrollbar thumb over the track.
Part part, virtual void PaintScrollbarThumb(skia::PlatformCanvas* canvas,
State state, Part part,
const gfx::Rect& rect); State state,
const gfx::Rect& rect);
// Draw the checkbox.
virtual void PaintCheckbox(skia::PlatformCanvas* canvas,
State state,
const gfx::Rect& rect,
const ButtonExtraParams& button);
// Draw the radio.
virtual void PaintRadio(skia::PlatformCanvas* canvas,
State state,
const gfx::Rect& rect,
const ButtonExtraParams& button);
// Draw the push button.
virtual void PaintButton(skia::PlatformCanvas* canvas,
State state,
const gfx::Rect& rect,
const ButtonExtraParams& button);
// Draw the text field.
virtual void PaintTextField(skia::PlatformCanvas* canvas,
State state,
const gfx::Rect& rect,
const TextFieldExtraParams& text);
// Draw the menu list.
virtual void PaintMenuList(skia::PlatformCanvas* canvas,
State state,
const gfx::Rect& rect,
const MenuListExtraParams& menu_list);
// Draw the slider track.
virtual void PaintSliderTrack(skia::PlatformCanvas* canvas,
State state,
const gfx::Rect& rect,
const SliderExtraParams& slider);
// Draw the slider thumb.
virtual void PaintSliderThumb(skia::PlatformCanvas* canvas,
State state,
const gfx::Rect& rect,
const SliderExtraParams& slider);
// Draw the inner spin button.
virtual void PaintInnerSpinButton(skia::PlatformCanvas* canvas,
State state,
const gfx::Rect& rect,
const InnerSpinButtonExtraParams& spin_button);
// Draw the progress bar.
virtual void PaintProgressBar(skia::PlatformCanvas* canvas,
State state,
const gfx::Rect& rect,
const ProgressBarExtraParams& progress_bar);
protected:
bool IntersectsClipRectInt(skia::PlatformCanvas* canvas,
int x, int y, int w, int h);
void DrawBitmapInt(skia::PlatformCanvas* canvas, const SkBitmap& bitmap,
int src_x, int src_y, int src_w, int src_h,
int dest_x, int dest_y, int dest_w, int dest_h);
void DrawTiledImage(SkCanvas* canvas,
const SkBitmap& bitmap,
int src_x, int src_y,
double tile_scale_x, double tile_scale_y,
int dest_x, int dest_y, int w, int h) const;
SkColor SaturateAndBrighten(SkScalar* hsv,
SkScalar saturate_amount,
SkScalar brighten_amount) const;
private: private:
void DrawVertLine(SkCanvas* canvas, void DrawVertLine(SkCanvas* canvas,
...@@ -106,9 +222,6 @@ class NativeThemeLinux { ...@@ -106,9 +222,6 @@ class NativeThemeLinux {
SkScalar Clamp(SkScalar value, SkScalar Clamp(SkScalar value,
SkScalar min, SkScalar min,
SkScalar max) const; SkScalar max) const;
SkColor SaturateAndBrighten(SkScalar* hsv,
SkScalar saturate_amount,
SkScalar brighten_amount) const;
SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const; SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const;
static unsigned int scrollbar_width_; static unsigned int scrollbar_width_;
......
...@@ -234,6 +234,14 @@ Point Rect::CenterPoint() const { ...@@ -234,6 +234,14 @@ Point Rect::CenterPoint() const {
return Point(x() + (width() + 1) / 2, y() + (height() + 1) / 2); return Point(x() + (width() + 1) / 2, y() + (height() + 1) / 2);
} }
Rect Rect::Center(const gfx::Size& size) const {
int new_width = std::min(width(), size.width());
int new_height = std::min(height(), size.height());
int new_x = x() + (width() - new_width) / 2;
int new_y = y() + (height() - new_height) / 2;
return Rect(new_x, new_y, new_width, new_height);
}
bool Rect::SharesEdgeWith(const gfx::Rect& rect) const { bool Rect::SharesEdgeWith(const gfx::Rect& rect) const {
return (y() == rect.y() && height() == rect.height() && return (y() == rect.y() && height() == rect.height() &&
(x() == rect.right() || right() == rect.x())) || (x() == rect.right() || right() == rect.x())) ||
......
...@@ -164,6 +164,10 @@ class Rect { ...@@ -164,6 +164,10 @@ class Rect {
// Returns the center of this rectangle. // Returns the center of this rectangle.
Point CenterPoint() const; Point CenterPoint() const;
// Return a rectangle that has the same center point but with a size capped
// at given |size|.
Rect Center(const gfx::Size& size) const;
// Returns true if this rectangle shares an entire edge (i.e., same width or // Returns true if this rectangle shares an entire edge (i.e., same width or
// same height) with the given rectangle, and the rectangles do not overlap. // same height) with the given rectangle, and the rectangles do not overlap.
bool SharesEdgeWith(const gfx::Rect& rect) const; bool SharesEdgeWith(const gfx::Rect& rect) const;
......
...@@ -38,6 +38,24 @@ static gfx::NativeThemeLinux::Part NativeThemePart( ...@@ -38,6 +38,24 @@ static gfx::NativeThemeLinux::Part NativeThemePart(
return gfx::NativeThemeLinux::kScrollbarHorizontalTrack; return gfx::NativeThemeLinux::kScrollbarHorizontalTrack;
case WebKit::WebThemeEngine::PartScrollbarVerticalTrack: case WebKit::WebThemeEngine::PartScrollbarVerticalTrack:
return gfx::NativeThemeLinux::kScrollbarVerticalTrack; return gfx::NativeThemeLinux::kScrollbarVerticalTrack;
case WebKit::WebThemeEngine::PartCheckbox:
return gfx::NativeThemeLinux::kCheckbox;
case WebKit::WebThemeEngine::PartRadio:
return gfx::NativeThemeLinux::kRadio;
case WebKit::WebThemeEngine::PartButton:
return gfx::NativeThemeLinux::kPushButton;
case WebKit::WebThemeEngine::PartTextField:
return gfx::NativeThemeLinux::kTextField;
case WebKit::WebThemeEngine::PartMenuList:
return gfx::NativeThemeLinux::kMenuList;
case WebKit::WebThemeEngine::PartSliderTrack:
return gfx::NativeThemeLinux::kSliderTrack;
case WebKit::WebThemeEngine::PartSliderThumb:
return gfx::NativeThemeLinux::kSliderThumb;
case WebKit::WebThemeEngine::PartInnerSpinButton:
return gfx::NativeThemeLinux::kInnerSpinButton;
case WebKit::WebThemeEngine::PartProgressBar:
return gfx::NativeThemeLinux::kProgressBar;
default: default:
return gfx::NativeThemeLinux::kScrollbarDownArrow; return gfx::NativeThemeLinux::kScrollbarDownArrow;
} }
...@@ -49,7 +67,7 @@ static gfx::NativeThemeLinux::State NativeThemeState( ...@@ -49,7 +67,7 @@ static gfx::NativeThemeLinux::State NativeThemeState(
case WebKit::WebThemeEngine::StateDisabled: case WebKit::WebThemeEngine::StateDisabled:
return gfx::NativeThemeLinux::kDisabled; return gfx::NativeThemeLinux::kDisabled;
case WebKit::WebThemeEngine::StateHover: case WebKit::WebThemeEngine::StateHover:
return gfx::NativeThemeLinux::kHover; return gfx::NativeThemeLinux::kHovered;
case WebKit::WebThemeEngine::StateNormal: case WebKit::WebThemeEngine::StateNormal:
return gfx::NativeThemeLinux::kNormal; return gfx::NativeThemeLinux::kNormal;
case WebKit::WebThemeEngine::StatePressed: case WebKit::WebThemeEngine::StatePressed:
...@@ -64,21 +82,79 @@ static void GetNativeThemeExtraParams( ...@@ -64,21 +82,79 @@ static void GetNativeThemeExtraParams(
WebKit::WebThemeEngine::State state, WebKit::WebThemeEngine::State state,
const WebKit::WebThemeEngine::ExtraParams* extra_params, const WebKit::WebThemeEngine::ExtraParams* extra_params,
gfx::NativeThemeLinux::ExtraParams* native_theme_extra_params) { gfx::NativeThemeLinux::ExtraParams* native_theme_extra_params) {
if (part == WebKit::WebThemeEngine::PartScrollbarHorizontalTrack || switch (part) {
part == WebKit::WebThemeEngine::PartScrollbarVerticalTrack) { case WebKit::WebThemeEngine::PartScrollbarHorizontalTrack:
native_theme_extra_params->scrollbar_track.track_x = case WebKit::WebThemeEngine::PartScrollbarVerticalTrack:
extra_params->scrollbarTrack.trackX; native_theme_extra_params->scrollbar_track.track_x =
native_theme_extra_params->scrollbar_track.track_y = extra_params->scrollbarTrack.trackX;
extra_params->scrollbarTrack.trackY; native_theme_extra_params->scrollbar_track.track_y =
native_theme_extra_params->scrollbar_track.track_width = extra_params->scrollbarTrack.trackY;
extra_params->scrollbarTrack.trackWidth; native_theme_extra_params->scrollbar_track.track_width =
native_theme_extra_params->scrollbar_track.track_height = extra_params->scrollbarTrack.trackWidth;
extra_params->scrollbarTrack.trackHeight; native_theme_extra_params->scrollbar_track.track_height =
extra_params->scrollbarTrack.trackHeight;
break;
case WebKit::WebThemeEngine::PartCheckbox:
native_theme_extra_params->button.checked = extra_params->button.checked;
native_theme_extra_params->button.indeterminate =
extra_params->button.indeterminate;
break;
case WebKit::WebThemeEngine::PartRadio:
native_theme_extra_params->button.checked = extra_params->button.checked;
break;
case WebKit::WebThemeEngine::PartButton:
native_theme_extra_params->button.is_default =
extra_params->button.isDefault;
native_theme_extra_params->button.background_color =
extra_params->button.backgroundColor;
break;
case WebKit::WebThemeEngine::PartTextField:
native_theme_extra_params->text_field.is_text_area =
extra_params->textField.isTextArea;
native_theme_extra_params->text_field.is_listbox =
extra_params->textField.isListbox;
native_theme_extra_params->text_field.background_color =
extra_params->textField.backgroundColor;
break;
case WebKit::WebThemeEngine::PartMenuList:
native_theme_extra_params->menu_list.arrow_x =
extra_params->menuList.arrowX;
native_theme_extra_params->menu_list.arrow_y =
extra_params->menuList.arrowY;
native_theme_extra_params->menu_list.background_color =
extra_params->menuList.backgroundColor;
break;
case WebKit::WebThemeEngine::PartSliderTrack:
case WebKit::WebThemeEngine::PartSliderThumb:
native_theme_extra_params->slider.vertical =
extra_params->slider.vertical;
native_theme_extra_params->slider.in_drag = extra_params->slider.inDrag;
break;
case WebKit::WebThemeEngine::PartInnerSpinButton:
native_theme_extra_params->inner_spin.spin_up =
extra_params->innerSpin.spinUp;
native_theme_extra_params->inner_spin.read_only =
extra_params->innerSpin.readOnly;
break;
case WebKit::WebThemeEngine::PartProgressBar:
native_theme_extra_params->progress_bar.determinate =
extra_params->progressBar.determinate;
native_theme_extra_params->progress_bar.value_rect_x =
extra_params->progressBar.valueRectX;
native_theme_extra_params->progress_bar.value_rect_y =
extra_params->progressBar.valueRectY;
native_theme_extra_params->progress_bar.value_rect_width =
extra_params->progressBar.valueRectWidth;
native_theme_extra_params->progress_bar.value_rect_height =
extra_params->progressBar.valueRectHeight;
break;
default:
break; // Parts that have no extra params get here.
} }
} }
WebKit::WebSize WebThemeEngineImpl::getSize(WebKit::WebThemeEngine::Part part) { WebKit::WebSize WebThemeEngineImpl::getSize(WebKit::WebThemeEngine::Part part) {
return gfx::NativeThemeLinux::instance()->GetSize(NativeThemePart(part)); return gfx::NativeThemeLinux::instance()->GetPartSize(NativeThemePart(part));
} }
void WebThemeEngineImpl::paint( void WebThemeEngineImpl::paint(
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/path_service.h" #include "base/path_service.h"
#include "base/string16.h" #include "base/string16.h"
#include "base/string_piece.h" #include "base/string_piece.h"
#include "gfx/gfx_module.h"
#include "grit/webkit_resources.h" #include "grit/webkit_resources.h"
namespace { namespace {
...@@ -18,6 +19,13 @@ namespace { ...@@ -18,6 +19,13 @@ namespace {
// Data resources on linux. This is a pointer to the mmapped resources file. // Data resources on linux. This is a pointer to the mmapped resources file.
app::DataPack* g_resource_data_pack = NULL; app::DataPack* g_resource_data_pack = NULL;
base::StringPiece TestResourceProvider(int resource_id) {
base::StringPiece res;
if (g_resource_data_pack)
g_resource_data_pack->GetStringPiece(resource_id, &res);
return res;
}
} }
namespace webkit_support { namespace webkit_support {
...@@ -37,6 +45,9 @@ void AfterInitialize(bool unit_test_mode) { ...@@ -37,6 +45,9 @@ void AfterInitialize(bool unit_test_mode) {
data_path = data_path.Append("DumpRenderTree.pak"); data_path = data_path.Append("DumpRenderTree.pak");
if (!g_resource_data_pack->Load(data_path)) if (!g_resource_data_pack->Load(data_path))
LOG(FATAL) << "failed to load DumpRenderTree.pak"; LOG(FATAL) << "failed to load DumpRenderTree.pak";
// Config the modules that need access to a limited set of resources.
gfx::GfxModule::SetResourceProvider(TestResourceProvider);
} }
void BeforeShutdown() { void BeforeShutdown() {
......
...@@ -176,6 +176,7 @@ ...@@ -176,6 +176,7 @@
'action_name': 'test_shell_repack', 'action_name': 'test_shell_repack',
'variables': { 'variables': {
'pak_inputs': [ 'pak_inputs': [
'<(SHARED_INTERMEDIATE_DIR)/gfx/gfx_resources.pak',
'<(SHARED_INTERMEDIATE_DIR)/net/net_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/net/net_resources.pak',
'<(SHARED_INTERMEDIATE_DIR)/test_shell/test_shell_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/test_shell/test_shell_resources.pak',
'<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_chromium_resources.pak', '<(SHARED_INTERMEDIATE_DIR)/webkit/webkit_chromium_resources.pak',
...@@ -331,6 +332,7 @@ ...@@ -331,6 +332,7 @@
], ],
}, { # OS != "mac" }, { # OS != "mac"
'dependencies': [ 'dependencies': [
'<(DEPTH)/gfx/gfx.gyp:gfx_resources',
'<(DEPTH)/net/net.gyp:net_resources', '<(DEPTH)/net/net.gyp:net_resources',
'<(DEPTH)/webkit/support/webkit_support.gyp:webkit_resources', '<(DEPTH)/webkit/support/webkit_support.gyp:webkit_resources',
'<(DEPTH)/webkit/support/webkit_support.gyp:webkit_strings', '<(DEPTH)/webkit/support/webkit_support.gyp:webkit_strings',
......
...@@ -360,8 +360,8 @@ public: ...@@ -360,8 +360,8 @@ public:
// Show the "attach to me" dialog, for debugging test shell startup. // Show the "attach to me" dialog, for debugging test shell startup.
static void ShowStartupDebuggingDialog(); static void ShowStartupDebuggingDialog();
// This is called indirectly by the network layer to access resources. // This is called indirectly by the modules that need access resources.
static base::StringPiece NetResourceProvider(int key); static base::StringPiece ResourceProvider(int key);
TestShellDevToolsAgent* dev_tools_agent() { TestShellDevToolsAgent* dev_tools_agent() {
return dev_tools_agent_.get(); return dev_tools_agent_.get();
......
...@@ -626,7 +626,7 @@ void TestShell::ShowStartupDebuggingDialog() { ...@@ -626,7 +626,7 @@ void TestShell::ShowStartupDebuggingDialog() {
} }
// static // static
base::StringPiece TestShell::NetResourceProvider(int key) { base::StringPiece TestShell::ResourceProvider(int key) {
base::StringPiece res; base::StringPiece res;
g_resource_data_pack->GetStringPiece(key, &res); g_resource_data_pack->GetStringPiece(key, &res);
return res; return res;
...@@ -655,7 +655,7 @@ base::StringPiece GetDataResource(int resource_id) { ...@@ -655,7 +655,7 @@ base::StringPiece GetDataResource(int resource_id) {
resource_id = IDR_TEXTAREA_RESIZER_TESTSHELL; resource_id = IDR_TEXTAREA_RESIZER_TESTSHELL;
break; break;
} }
return TestShell::NetResourceProvider(resource_id); return TestShell::ResourceProvider(resource_id);
} }
} // namespace webkit_glue } // namespace webkit_glue
...@@ -654,7 +654,7 @@ void TestShell::ShowStartupDebuggingDialog() { ...@@ -654,7 +654,7 @@ void TestShell::ShowStartupDebuggingDialog() {
[alert runModal]; [alert runModal];
} }
base::StringPiece TestShell::NetResourceProvider(int key) { base::StringPiece TestShell::ResourceProvider(int key) {
base::StringPiece res; base::StringPiece res;
g_resource_data_pack->GetStringPiece(key, &res); g_resource_data_pack->GetStringPiece(key, &res);
return res; return res;
...@@ -721,7 +721,7 @@ base::StringPiece GetDataResource(int resource_id) { ...@@ -721,7 +721,7 @@ base::StringPiece GetDataResource(int resource_id) {
case IDR_INPUT_SPEECH: case IDR_INPUT_SPEECH:
case IDR_INPUT_SPEECH_RECORDING: case IDR_INPUT_SPEECH_RECORDING:
case IDR_INPUT_SPEECH_WAITING: case IDR_INPUT_SPEECH_WAITING:
return TestShell::NetResourceProvider(resource_id); return TestShell::ResourceProvider(resource_id);
default: default:
break; break;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "base/string_number_conversions.h" #include "base/string_number_conversions.h"
#include "base/sys_info.h" #include "base/sys_info.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "gfx/gfx_module.h"
#include "net/base/cookie_monster.h" #include "net/base/cookie_monster.h"
#include "net/base/net_module.h" #include "net/base/net_module.h"
#include "net/base/net_util.h" #include "net/base/net_util.h"
...@@ -202,8 +203,9 @@ int main(int argc, char* argv[]) { ...@@ -202,8 +203,9 @@ int main(int argc, char* argv[]) {
// Load ICU data tables // Load ICU data tables
icu_util::Initialize(); icu_util::Initialize();
// Config the network module so it has access to a limited set of resources. // Config the modules that need access to a limited set of resources.
net::NetModule::SetResourceProvider(TestShell::NetResourceProvider); net::NetModule::SetResourceProvider(TestShell::ResourceProvider);
gfx::GfxModule::SetResourceProvider(TestShell::ResourceProvider);
platform.InitializeGUI(); platform.InitializeGUI();
......
...@@ -138,11 +138,6 @@ static base::StringPiece GetRawDataResource(HMODULE module, int resource_id) { ...@@ -138,11 +138,6 @@ static base::StringPiece GetRawDataResource(HMODULE module, int resource_id) {
: base::StringPiece(); : base::StringPiece();
} }
// This is called indirectly by the network layer to access resources.
base::StringPiece NetResourceProvider(int key) {
return GetRawDataResource(::GetModuleHandle(NULL), key);
}
} // namespace } // namespace
// Initialize static member variable // Initialize static member variable
...@@ -739,7 +734,7 @@ void TestShell::ShowStartupDebuggingDialog() { ...@@ -739,7 +734,7 @@ void TestShell::ShowStartupDebuggingDialog() {
} }
// static // static
base::StringPiece TestShell::NetResourceProvider(int key) { base::StringPiece TestShell::ResourceProvider(int key) {
return GetRawDataResource(::GetModuleHandle(NULL), key); return GetRawDataResource(::GetModuleHandle(NULL), key);
} }
...@@ -806,7 +801,7 @@ base::StringPiece GetDataResource(int resource_id) { ...@@ -806,7 +801,7 @@ base::StringPiece GetDataResource(int resource_id) {
case IDR_INPUT_SPEECH: case IDR_INPUT_SPEECH:
case IDR_INPUT_SPEECH_RECORDING: case IDR_INPUT_SPEECH_RECORDING:
case IDR_INPUT_SPEECH_WAITING: case IDR_INPUT_SPEECH_WAITING:
return NetResourceProvider(resource_id); return TestShell::ResourceProvider(resource_id);
default: default:
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment