summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortkent@chromium.org <tkent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-14 06:45:57 +0000
committertkent@chromium.org <tkent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-14 06:45:57 +0000
commit1e21ff4117eb97eec232aeb761cbbc60db8869f5 (patch)
tree50c18292811e389861b894c74f63d4bb7e530225
parente3712a768be3688524e6a75e0d29f72dafd320ef (diff)
downloadchromium_src-1e21ff4117eb97eec232aeb761cbbc60db8869f5.zip
chromium_src-1e21ff4117eb97eec232aeb761cbbc60db8869f5.tar.gz
chromium_src-1e21ff4117eb97eec232aeb761cbbc60db8869f5.tar.bz2
Added support for HTML5 progress element.
WebKit side of this change is on http://webkit.org/b/37308 . continued from http://codereview.chromium.org/1596018 Patch by Hajime Morita <morrita@g> Original code review: http://codereview.chromium.org/1988012/show BUG=none TEST=Covered by WebKit LayoutTests git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47247 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--gfx/native_theme_win.cc55
-rw-r--r--gfx/native_theme_win.h9
-rw-r--r--webkit/glue/webthemeengine_impl_win.cc17
-rw-r--r--webkit/glue/webthemeengine_impl_win.h4
-rw-r--r--webkit/tools/test_shell/test_shell_webthemecontrol.cc29
-rw-r--r--webkit/tools/test_shell/test_shell_webthemecontrol.h17
-rw-r--r--webkit/tools/test_shell/test_shell_webthemeengine.cc25
-rw-r--r--webkit/tools/test_shell/test_shell_webthemeengine.h6
8 files changed, 145 insertions, 17 deletions
diff --git a/gfx/native_theme_win.cc b/gfx/native_theme_win.cc
index ec70b2f..07deec1 100644
--- a/gfx/native_theme_win.cc
+++ b/gfx/native_theme_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -478,6 +478,56 @@ HRESULT NativeTheme::PaintTrackbar(HDC hdc,
return S_OK;
}
+// A ScopedRegion wrapper to set/restore clipping region during the scope.
+class ScopedRegionClipping {
+ public:
+ explicit ScopedRegionClipping(const HDC hdc)
+ : hdc_(hdc), clip_(NULL) {
+ RECT zero_rect = { 0 };
+ clip_ = CreateRectRgnIndirect(&zero_rect);
+ GetClipRgn(hdc_, clip_);
+ }
+
+ ~ScopedRegionClipping() {
+ SelectClipRgn(hdc_, clip_);
+ }
+
+ private:
+ HDC hdc_;
+ ScopedRegion clip_;
+ DISALLOW_COPY_AND_ASSIGN(ScopedRegionClipping);
+};
+
+HRESULT NativeTheme::PaintProgressBar(HDC hdc,
+ RECT* bar_rect,
+ int value_part_id,
+ RECT* value_rect,
+ skia::PlatformCanvas* canvas) const {
+ // For an indeterminate progress bar, we draw a moving highlight that's animated
+ // (by the caller) across the width of the bar. The highlight part is always
+ // drawn as being as wide as the bar, to scale it properly. Therefore, we need
+ // to clip it against the bar rect, so that as it moves, it doesn't extend past
+ // the ends of the bar. For a normal progress bar, we won't try to draw past
+ // the bar ends, so this clipping is useless, but harmless.
+ ScopedRegionClipping clip(hdc);
+ IntersectClipRect(hdc, bar_rect->left, bar_rect->top,
+ bar_rect->right, bar_rect->bottom);
+
+ HANDLE handle = GetThemeHandle(PROGRESS);
+ if (handle && draw_theme_) {
+ draw_theme_(handle, hdc, PP_BAR, 0, bar_rect, NULL);
+ draw_theme_(handle, hdc, value_part_id, 0, value_rect, NULL);
+ return S_OK;
+ }
+
+ HBRUSH bg_brush = GetSysColorBrush(COLOR_BTNFACE);
+ HBRUSH fg_brush = GetSysColorBrush(COLOR_BTNSHADOW);
+ FillRect(hdc, bar_rect, bg_brush);
+ FillRect(hdc, value_rect, fg_brush);
+ DrawEdge(hdc, bar_rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
+ return S_OK;
+}
+
HRESULT NativeTheme::PaintTextField(HDC hdc,
int part_id,
int state_id,
@@ -707,6 +757,9 @@ HANDLE NativeTheme::GetThemeHandle(ThemeName theme_name) const
case WINDOW:
handle = open_theme_(NULL, L"Window");
break;
+ case PROGRESS:
+ handle = open_theme_(NULL, L"Progress");
+ break;
default:
NOTREACHED();
}
diff --git a/gfx/native_theme_win.h b/gfx/native_theme_win.h
index 8dd320b..b98b138 100644
--- a/gfx/native_theme_win.h
+++ b/gfx/native_theme_win.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
//
@@ -43,6 +43,7 @@ class NativeTheme {
TEXTFIELD,
TRACKBAR,
WINDOW,
+ PROGRESS,
LAST
};
@@ -207,6 +208,12 @@ class NativeTheme {
RECT* rect,
skia::PlatformCanvas* canvas) const;
+ HRESULT PaintProgressBar(HDC hdc,
+ RECT* bar_rect,
+ int value_part_id,
+ RECT* value_rect,
+ skia::PlatformCanvas* canvas) const;
+
bool IsThemingActive() const;
HRESULT GetThemePartSize(ThemeName themeName,
diff --git a/webkit/glue/webthemeengine_impl_win.cc b/webkit/glue/webthemeengine_impl_win.cc
index 78d7cf3614..0d2b563 100644
--- a/webkit/glue/webthemeengine_impl_win.cc
+++ b/webkit/glue/webthemeengine_impl_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
+// Copyright (c) 2010 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.
@@ -114,4 +114,19 @@ void WebThemeEngineImpl::paintTrackbar(
canvas->endPlatformPaint();
}
+void WebThemeEngineImpl::paintProgressBar(
+ WebKit::WebCanvas* canvas,
+ const WebKit::WebRect& barRect,
+ int valuePart, const WebKit::WebRect& valueRect)
+
+{
+ HDC hdc = canvas->beginPlatformPaint();
+ RECT native_bar_rect = WebRectToRECT(barRect);
+ RECT native_value_rect = WebRectToRECT(valueRect);
+ gfx::NativeTheme::instance()->PaintProgressBar(
+ hdc, &native_bar_rect,
+ valuePart, &native_value_rect, canvas);
+ canvas->endPlatformPaint();
+}
+
} // namespace webkit_glue
diff --git a/webkit/glue/webthemeengine_impl_win.h b/webkit/glue/webthemeengine_impl_win.h
index ae9152b..73cb42d 100644
--- a/webkit/glue/webthemeengine_impl_win.h
+++ b/webkit/glue/webthemeengine_impl_win.h
@@ -34,6 +34,10 @@ class WebThemeEngineImpl : public WebKit::WebThemeEngine {
virtual void paintTrackbar(
WebKit::WebCanvas*, int part, int state, int classic_state,
const WebKit::WebRect&);
+ virtual void paintProgressBar(
+ WebKit::WebCanvas*,
+ const WebKit::WebRect& barRect,
+ int valuePart, const WebKit::WebRect& valueRect);
};
} // namespace webkit_glue
diff --git a/webkit/tools/test_shell/test_shell_webthemecontrol.cc b/webkit/tools/test_shell/test_shell_webthemecontrol.cc
index 742a295..96045f3 100644
--- a/webkit/tools/test_shell/test_shell_webthemecontrol.cc
+++ b/webkit/tools/test_shell/test_shell_webthemecontrol.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -30,7 +30,8 @@ const SkColor kBgColors[] = {
SkColorSetRGB(0x43, 0xf9, 0xff), // Hot
SkColorSetRGB(0x20, 0xf6, 0xcc), // Focused
SkColorSetRGB(0x00, 0xf3, 0xac), // Hover
- SkColorSetRGB(0xa9, 0xff, 0x12) // Pressed
+ SkColorSetRGB(0xa9, 0xff, 0x12), // Pressed
+ SkColorSetRGB(0xcc, 0xcc, 0xcc) // Indeterminate
};
SkIRect Validate(const SkIRect& rect, Control::Type ctype) {
@@ -53,7 +54,7 @@ SkIRect Validate(const SkIRect& rect, Control::Type ctype) {
return retval;
}
-Control::Control(skia::PlatformCanvas *canvas, const SkIRect &irect,
+Control::Control(skia::PlatformCanvas* canvas, const SkIRect& irect,
Type ctype, State cstate)
: canvas_(canvas),
irect_(Validate(irect, ctype)),
@@ -73,7 +74,7 @@ Control::Control(skia::PlatformCanvas *canvas, const SkIRect &irect,
Control::~Control() {
}
-void Control::box(const SkIRect &rect, SkColor fill_color) {
+void Control::box(const SkIRect& rect, SkColor fill_color) {
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
@@ -411,5 +412,25 @@ void Control::drawTextField(bool draw_edges, bool fill_content_area,
canvas_->endPlatformPaint();
}
+void
+Control::drawProgressBar(const SkIRect& fill_rect) {
+ SkPaint paint;
+
+ canvas_->beginPlatformPaint();
+ paint.setColor(bg_color_);
+ paint.setStyle(SkPaint::kFill_Style);
+ canvas_->drawIRect(irect_, paint);
+
+ // Emulate clipping
+ SkIRect tofill;
+ tofill.intersect(irect_, fill_rect);
+ paint.setColor(fg_color_);
+ paint.setStyle(SkPaint::kFill_Style);
+ canvas_->drawIRect(tofill, paint);
+
+ markState();
+ canvas_->endPlatformPaint();
+}
+
} // namespace TestShellWebTheme
diff --git a/webkit/tools/test_shell/test_shell_webthemecontrol.h b/webkit/tools/test_shell/test_shell_webthemecontrol.h
index bb439af..ddb8633 100644
--- a/webkit/tools/test_shell/test_shell_webthemecontrol.h
+++ b/webkit/tools/test_shell/test_shell_webthemecontrol.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -43,6 +43,7 @@ class Control {
// Focused - when the control has the keyboard focus
// Pressed - when the control is being triggered (by a mousedown or
// a key event).
+ // Indeterminate - when set to indeterminate (only for progress bar)
enum State {
kUnknown_State = 0,
kDisabled_State,
@@ -51,7 +52,8 @@ class Control {
kHot_State,
kHover_State,
kFocused_State,
- kPressed_State
+ kPressed_State,
+ kIndeterminate_State
};
// This list of types mostly mirrors the list in
@@ -86,12 +88,13 @@ class Control {
kDownArrow_Type,
kHorizontalSliderTrack_Type,
kHorizontalSliderThumb_Type,
- kDropDownButton_Type
+ kDropDownButton_Type,
+ kProgressBar_Type
};
// canvas is the canvas to draw onto, and rect gives the size of the
// control. ctype and cstate specify the type and state of the control.
- Control(skia::PlatformCanvas *canvas, const SkIRect &rect,
+ Control(skia::PlatformCanvas* canvas, const SkIRect& rect,
Type ctype, State cstate);
~Control();
@@ -104,10 +107,14 @@ class Control {
// fill_content_area is true, fill the content area with the given color.
void drawTextField(bool draw_edges, bool fill_content_area, SkColor color);
+ // Use this for drawing ProgressBar controls instead, since we
+ // need to know the rect to fill inside the bar.
+ void drawProgressBar(const SkIRect& fill_rect);
+
private:
// Draws a box of size specified by irect, filled with the given color.
// The box will have a border drawn in the default edge color.
- void box(const SkIRect &irect, SkColor color);
+ void box(const SkIRect& irect, SkColor color);
// Draws a triangle of size specified by the three pairs of coordinates,
diff --git a/webkit/tools/test_shell/test_shell_webthemeengine.cc b/webkit/tools/test_shell/test_shell_webthemeengine.cc
index b9e0308..8c457a8 100644
--- a/webkit/tools/test_shell/test_shell_webthemeengine.cc
+++ b/webkit/tools/test_shell/test_shell_webthemeengine.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -40,26 +40,33 @@ using WebKit::WebRect;
namespace TestShellWebTheme {
-SkIRect webRectToSkIRect(const WebRect &web_rect) {
+SkIRect webRectToSkIRect(const WebRect& web_rect) {
SkIRect irect;
irect.set(web_rect.x, web_rect.y, web_rect.x + web_rect.width,
web_rect.y + web_rect.height);
return irect;
}
-void drawControl(WebCanvas *canvas, const WebRect &rect, Control::Type ctype,
+void drawControl(WebCanvas* canvas, const WebRect& rect, Control::Type ctype,
Control::State cstate) {
Control control(canvas, webRectToSkIRect(rect), ctype, cstate);
control.draw();
}
-void drawTextField(WebCanvas *canvas, const WebRect &rect,
+void drawTextField(WebCanvas* canvas, const WebRect& rect,
Control::Type ctype, Control::State cstate,
bool draw_edges, bool fill_content_area, WebColor color) {
Control control(canvas, webRectToSkIRect(rect), ctype, cstate);
control.drawTextField(draw_edges, fill_content_area, color);
}
+void drawProgressBar(WebCanvas* canvas,
+ Control::Type ctype, Control::State cstate,
+ const WebRect& bar_rect, const WebRect& fill_rect) {
+ Control control(canvas, webRectToSkIRect(bar_rect), ctype, cstate);
+ control.drawProgressBar(webRectToSkIRect(fill_rect));
+}
+
void Engine::paintButton(WebCanvas* canvas, int part, int state,
int classic_state, const WebRect& rect) {
Control::Type ctype = Control::kUnknown_Type;
@@ -533,4 +540,14 @@ void Engine::paintTrackbar(WebCanvas* canvas, int part, int state,
drawControl(canvas, rect, ctype, cstate);
}
+
+void Engine::paintProgressBar(WebKit::WebCanvas* canvas,
+ const WebKit::WebRect& barRect,
+ int valuePart, const WebKit::WebRect& valueRect) {
+ Control::Type ctype = Control::kProgressBar_Type;
+ Control::State cstate = valuePart == PP_FILL ?
+ Control::kNormal_State : Control::kIndeterminate_State;
+ drawProgressBar(canvas, ctype, cstate, barRect, valueRect);
+}
+
} // namespace TestShellWebTheme
diff --git a/webkit/tools/test_shell/test_shell_webthemeengine.h b/webkit/tools/test_shell/test_shell_webthemeengine.h
index 6983b01..2d4223d 100644
--- a/webkit/tools/test_shell/test_shell_webthemeengine.h
+++ b/webkit/tools/test_shell/test_shell_webthemeengine.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -53,6 +53,10 @@ class Engine : public WebKit::WebThemeEngine {
virtual void paintTrackbar(
WebKit::WebCanvas*, int part, int state, int classic_state,
const WebKit::WebRect&);
+ virtual void paintProgressBar(
+ WebKit::WebCanvas*,
+ const WebKit::WebRect& barRect,
+ int valuePart, const WebKit::WebRect& valueRect);
private:
DISALLOW_COPY_AND_ASSIGN(Engine);