diff options
author | tkent@chromium.org <tkent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-19 03:08:03 +0000 |
---|---|---|
committer | tkent@chromium.org <tkent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-19 03:08:03 +0000 |
commit | fd9f1e87703a5c78b2626135723b586bdd59c7b7 (patch) | |
tree | a9d4d369737b2f88c59d3aad6c5f56c0450b2034 | |
parent | ef8561def41e78e9a56939246d3331703ab93c0d (diff) | |
download | chromium_src-fd9f1e87703a5c78b2626135723b586bdd59c7b7.zip chromium_src-fd9f1e87703a5c78b2626135723b586bdd59c7b7.tar.gz chromium_src-fd9f1e87703a5c78b2626135723b586bdd59c7b7.tar.bz2 |
- Draw glossy animation effect for determinate progress bar
- Moved animation code for indeterminate bar from WebKit
because adding change above makes webkit-side
too complicated.
Note:
- This change depends https://webkit.org/b/39269
- Appearance of indeterminate bar remains incorrect.
I filed it to http://crbug.com/44433.
Patch by Hajime Morita <morrita@g>
Original code review: http://codereview.chromium.org/2131008/show
BUG=44430
TEST=none
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47618 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | gfx/native_theme_win.cc | 86 | ||||
-rw-r--r-- | gfx/native_theme_win.h | 3 | ||||
-rw-r--r-- | webkit/glue/webthemeengine_impl_win.cc | 16 | ||||
-rw-r--r-- | webkit/glue/webthemeengine_impl_win.h | 6 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webthemeengine.cc | 11 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webthemeengine.h | 6 |
6 files changed, 76 insertions, 52 deletions
diff --git a/gfx/native_theme_win.cc b/gfx/native_theme_win.cc index a8e90ad..57a5c2f 100644 --- a/gfx/native_theme_win.cc +++ b/gfx/native_theme_win.cc @@ -478,46 +478,70 @@ HRESULT NativeTheme::PaintTrackbar(HDC hdc, return S_OK; } -// A ScopedRegion wrapper to set/restore clipping region during the scope. -class ScopedClipRegion { - public: - explicit ScopedClipRegion(const HDC hdc) - : hdc_(hdc), clip_(NULL) { - RECT zero_rect = { 0 }; - clip_ = CreateRectRgnIndirect(&zero_rect); - GetClipRgn(hdc_, clip_); - } - - ~ScopedClipRegion() { - SelectClipRgn(hdc_, clip_); - } - - private: - HDC hdc_; - ScopedRegion clip_; - DISALLOW_COPY_AND_ASSIGN(ScopedClipRegion); -}; +// <-a-> +// [ ***** ] +// ____ | | +// <-a-> <------b-----> +// a: object_width +// b: frame_width +// *: animating object +// +// - the animation goes from "[" to "]" repeatedly. +// - the animation offset is at first "|" +// +static int ComputeAnimationProgress(int frame_width, + int object_width, + int pixels_per_second, + double animated_seconds) { + int animation_width = frame_width + object_width; + double interval = static_cast<double>(animation_width) / pixels_per_second; + double ratio = fmod(animated_seconds, interval) / interval; + return static_cast<int>(animation_width * ratio) - object_width; +} HRESULT NativeTheme::PaintProgressBar(HDC hdc, RECT* bar_rect, - int value_part_id, RECT* value_rect, + bool determinate, + double animated_seconds, 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. - ScopedClipRegion clip(hdc); - IntersectClipRect(hdc, bar_rect->left, bar_rect->top, - bar_rect->right, bar_rect->bottom); + // There is no documentation about the animation speed, frame-rate, nor + // size of moving overlay of the indeterminate progress bar. + // So we just observed real-world programs and guessed following parameters. + const int kDeteminateOverlayPixelsPerSecond = 300; + const int kDeteminateOverlayWidth = 120; + const int kIndeterminateOverlayPixelsPerSecond = 175; + const int kIndeterminateOverlayWidth = 120; 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); + + int bar_width = bar_rect->right - bar_rect->left; + if (determinate) { + draw_theme_(handle, hdc, PP_FILL, 0, value_rect, bar_rect); + int dx = ComputeAnimationProgress(bar_width, + kDeteminateOverlayWidth, + kDeteminateOverlayPixelsPerSecond, + animated_seconds); + RECT overlay_rect = *value_rect; + overlay_rect.left += dx; + overlay_rect.right = overlay_rect.left + kDeteminateOverlayWidth; + draw_theme_(handle, hdc, PP_MOVEOVERLAY, 0, &overlay_rect, value_rect); + } else { + // A glossy overlay for determinate progress bar as small pause + // during each interval. we emulate it using a margin value. + int width_with_margin = bar_width + kIndeterminateOverlayPixelsPerSecond; + int dx = ComputeAnimationProgress(width_with_margin, + kIndeterminateOverlayWidth, + kIndeterminateOverlayPixelsPerSecond, + animated_seconds); + RECT overlay_rect = *bar_rect; + overlay_rect.left += dx; + overlay_rect.right = overlay_rect.left + kIndeterminateOverlayWidth; + draw_theme_(handle, hdc, PP_MOVEOVERLAY, 0, &overlay_rect, bar_rect); + } + return S_OK; } diff --git a/gfx/native_theme_win.h b/gfx/native_theme_win.h index b98b138..6df247d 100644 --- a/gfx/native_theme_win.h +++ b/gfx/native_theme_win.h @@ -210,8 +210,9 @@ class NativeTheme { HRESULT PaintProgressBar(HDC hdc, RECT* bar_rect, - int value_part_id, RECT* value_rect, + bool determinate, + double animated_seconds, skia::PlatformCanvas* canvas) const; bool IsThemingActive() const; diff --git a/webkit/glue/webthemeengine_impl_win.cc b/webkit/glue/webthemeengine_impl_win.cc index 0d2b563..71913ef 100644 --- a/webkit/glue/webthemeengine_impl_win.cc +++ b/webkit/glue/webthemeengine_impl_win.cc @@ -1,6 +1,6 @@ -// 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. +// 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. #include "webkit/glue/webthemeengine_impl_win.h" @@ -115,17 +115,15 @@ void WebThemeEngineImpl::paintTrackbar( } void WebThemeEngineImpl::paintProgressBar( - WebKit::WebCanvas* canvas, - const WebKit::WebRect& barRect, - int valuePart, const WebKit::WebRect& valueRect) - + WebCanvas* canvas, const WebRect& barRect, const WebRect& valueRect, + bool determinate, double animatedSeconds) { 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); + hdc, &native_bar_rect, + &native_value_rect, determinate, animatedSeconds, canvas); canvas->endPlatformPaint(); } diff --git a/webkit/glue/webthemeengine_impl_win.h b/webkit/glue/webthemeengine_impl_win.h index 73cb42d..b57b915 100644 --- a/webkit/glue/webthemeengine_impl_win.h +++ b/webkit/glue/webthemeengine_impl_win.h @@ -35,9 +35,9 @@ class WebThemeEngineImpl : public WebKit::WebThemeEngine { 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); + WebKit::WebCanvas*, const WebKit::WebRect& barRect, + const WebKit::WebRect& valueRect, bool determinate, + double animatedSeconds); }; } // namespace webkit_glue diff --git a/webkit/tools/test_shell/test_shell_webthemeengine.cc b/webkit/tools/test_shell/test_shell_webthemeengine.cc index 8c457a8..6deb9a8 100644 --- a/webkit/tools/test_shell/test_shell_webthemeengine.cc +++ b/webkit/tools/test_shell/test_shell_webthemeengine.cc @@ -543,11 +543,12 @@ void Engine::paintTrackbar(WebCanvas* canvas, int part, int state, 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); + const WebKit::WebRect& valueRect, + bool determinate, double) { + Control::Type ctype = Control::kProgressBar_Type; + Control::State cstate = + determinate ? 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 2d4223d..617cf7d 100644 --- a/webkit/tools/test_shell/test_shell_webthemeengine.h +++ b/webkit/tools/test_shell/test_shell_webthemeengine.h @@ -54,9 +54,9 @@ class Engine : public WebKit::WebThemeEngine { 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); + WebKit::WebCanvas*, const WebKit::WebRect& barRect, + const WebKit::WebRect& valueRect, + bool determinate, double time); private: DISALLOW_COPY_AND_ASSIGN(Engine); |