Commit 5e92282f authored by sail@chromium.org's avatar sail@chromium.org

Gradient overlay for constrained window

As a part of the new constrained window look and feel we're changing the the solid gray overlay to a gradient overlay. The overlay fades in on show and fades out on hide.

Screenshots:
    light background: http://i.imgur.com/GJj6L.png
    dark background: http://i.imgur.com/s37da.png

BUG=140520
TEST=Run with --enable-frameless-constrained-dialogs.
  Navigate to http://www.imagemator.com/
  Click "Click to pick an image."

Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=152059

Review URL: https://chromiumcodereview.appspot.com/10855151

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152065 0039d316-1c4b-4281-b951-d872f2087c98
parent 8fdd9a89
......@@ -850,6 +850,7 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
switches::kEnableBundledPpapiFlash,
switches::kEnableCrxlessWebApps,
switches::kEnableExperimentalExtensionApis,
switches::kEnableFramelessConstrainedDialogs,
switches::kEnableHighDPIPDFPlugin,
switches::kEnableIPCFuzzing,
switches::kEnableNaCl,
......
......@@ -270,6 +270,8 @@
'renderer/translate_helper.h',
'renderer/visitedlink_slave.cc',
'renderer/visitedlink_slave.h',
'renderer/webview_animating_overlay.cc',
'renderer/webview_animating_overlay.h',
'renderer/webview_color_overlay.cc',
'renderer/webview_color_overlay.h',
],
......
......@@ -3025,6 +3025,7 @@
'renderer/safe_browsing/phishing_dom_feature_extractor_browsertest.cc',
'renderer/safe_browsing/phishing_thumbnailer_browsertest.cc',
'renderer/translate_helper_browsertest.cc',
'renderer/webview_animating_overlay_browsertest.cc',
'test/base/empty_browser_test.cc',
'test/base/in_process_browser_test_browsertest.cc',
'test/base/chrome_render_view_test.cc',
......
......@@ -27,6 +27,7 @@
#include "chrome/renderer/prerender/prerender_helper.h"
#include "chrome/renderer/safe_browsing/phishing_classifier_delegate.h"
#include "chrome/renderer/translate_helper.h"
#include "chrome/renderer/webview_animating_overlay.h"
#include "chrome/renderer/webview_color_overlay.h"
#include "content/public/common/bindings_policy.h"
#include "content/public/renderer/render_view.h"
......@@ -381,6 +382,17 @@ void ChromeRenderViewObserver::OnSetClientSidePhishingDetection(
}
void ChromeRenderViewObserver::OnSetVisuallyDeemphasized(bool deemphasized) {
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableFramelessConstrainedDialogs)) {
if (!dimmed_animating_overlay_.get()) {
dimmed_animating_overlay_.reset(
new WebViewAnimatingOverlay(render_view()));
}
if (deemphasized)
dimmed_animating_overlay_->Show();
else
dimmed_animating_overlay_->Hide();
} else {
bool already_deemphasized = !!dimmed_color_overlay_.get();
if (already_deemphasized == deemphasized)
return;
......@@ -393,6 +405,7 @@ void ChromeRenderViewObserver::OnSetVisuallyDeemphasized(bool deemphasized) {
} else {
dimmed_color_overlay_.reset();
}
}
}
void ChromeRenderViewObserver::OnStartFrameSniffer(const string16& frame_name) {
......
......@@ -24,6 +24,7 @@ class SkBitmap;
class TranslateHelper;
struct ThumbnailScore;
class WebViewColorOverlay;
class WebViewAnimatingOverlay;
namespace extensions {
class Dispatcher;
......@@ -233,6 +234,9 @@ class ChromeRenderViewObserver : public content::RenderViewObserver,
// A color page overlay when visually de-emaphasized.
scoped_ptr<WebViewColorOverlay> dimmed_color_overlay_;
// A animating page overlay when visually de-emaphasized.
scoped_ptr<WebViewAnimatingOverlay> dimmed_animating_overlay_;
// Used to delay calling CapturePageInfo.
base::Timer capture_timer_;
......
// Copyright (c) 2012 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/renderer/webview_animating_overlay.h"
#include "base/logging.h"
#include "content/public/renderer/render_view.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkRect.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
#include "ui/gfx/size.h"
#include "ui/gfx/skia_util.h"
const int kAnimationDurationMiliseconds = 500;
const int kAnimationFrameRate = 60;
const int kTargetAlpha = 191;
WebViewAnimatingOverlay::WebViewAnimatingOverlay(
content::RenderView* render_view)
: render_view_(render_view),
state_(HIDDEN),
animation_(kAnimationDurationMiliseconds, kAnimationFrameRate, this) {
}
WebViewAnimatingOverlay::~WebViewAnimatingOverlay() {
if (render_view_->GetWebView())
render_view_->GetWebView()->removePageOverlay(this);
}
void WebViewAnimatingOverlay::Show() {
if (state_ == ANIMATING_IN || state_ == VISIBLE)
return;
if (state_ == ANIMATING_OUT) {
animation_.SetCurrentValue(1.0 - animation_.GetCurrentValue());
} else {
DCHECK_EQ(HIDDEN, state_);
if (render_view_->GetWebView())
render_view_->GetWebView()->addPageOverlay(this, 0);
}
state_ = ANIMATING_IN;
animation_.Start();
}
void WebViewAnimatingOverlay::Hide() {
if (state_ == ANIMATING_OUT || state_ == HIDDEN)
return;
if (state_ == ANIMATING_IN)
animation_.SetCurrentValue(1.0 - animation_.GetCurrentValue());
state_ = ANIMATING_OUT;
animation_.Start();
}
void WebViewAnimatingOverlay::paintPageOverlay(WebKit::WebCanvas* canvas) {
SkRect rect = gfx::RectToSkRect(gfx::Rect(render_view_->GetSize()));
// The center of the radial gradient should be near the top middle.
SkPoint center_point;
center_point.iset(rect.width() * 0.5, rect.height() * 0.05);
int radius = static_cast<int>(rect.width());
// Animate in or out using the alpha.
int alpha = GetCurrentAlpha();
SkColor colors[] = {
SkColorSetARGB(alpha, 255, 255, 255),
SkColorSetARGB(alpha, 127, 127, 127)
};
SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center_point,
SkIntToScalar(radius), colors, NULL, arraysize(colors),
SkShader::kClamp_TileMode));
SkPaint paint;
paint.setShader(shader);
paint.setDither(true);
canvas->drawRect(rect, paint);
}
void WebViewAnimatingOverlay::AnimationEnded(const ui::Animation* animation) {
if (state_ == ANIMATING_IN) {
state_ = VISIBLE;
} else {
DCHECK_EQ(ANIMATING_OUT, state_);
state_ = HIDDEN;
if (render_view_->GetWebView())
render_view_->GetWebView()->removePageOverlay(this);
}
}
void WebViewAnimatingOverlay::AnimationProgressed(
const ui::Animation* animation) {
render_view_->Repaint(render_view_->GetSize());
}
int WebViewAnimatingOverlay::GetCurrentAlpha() {
switch (state_) {
case ANIMATING_IN:
return animation_.CurrentValueBetween(0, kTargetAlpha);
case ANIMATING_OUT:
return animation_.CurrentValueBetween(kTargetAlpha, 0);
case VISIBLE:
case HIDDEN:
return kTargetAlpha;
}
NOTREACHED();
return 1.0;
}
// Copyright (c) 2012 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_RENDERER_WEBVIEW_ANIMATING_OVERLAY_H_
#define CHROME_RENDERER_WEBVIEW_ANIMATING_OVERLAY_H_
#include "base/compiler_specific.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPageOverlay.h"
#include "ui/base/animation/animation_delegate.h"
#include "ui/base/animation/linear_animation.h"
namespace content {
class RenderView;
}
// This class draws a gradient on a PageOverlay of a WebView. The gradient
// fades in when shown and fades out when hidden.
class WebViewAnimatingOverlay : public WebKit::WebPageOverlay,
public ui::AnimationDelegate {
public:
enum State {
ANIMATING_IN,
VISIBLE,
ANIMATING_OUT,
HIDDEN
};
explicit WebViewAnimatingOverlay(content::RenderView* render_view);
virtual ~WebViewAnimatingOverlay();
void Show();
void Hide();
State state() { return state_; }
// WebKit::WebPageOverlay implementation:
virtual void paintPageOverlay(WebKit::WebCanvas* canvas) OVERRIDE;
// ui::AnimationDelegate implementation:
virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE;
virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
private:
int GetCurrentAlpha();
content::RenderView* render_view_;
State state_;
ui::LinearAnimation animation_;
DISALLOW_COPY_AND_ASSIGN(WebViewAnimatingOverlay);
};
#endif // CHROME_RENDERER_WEBVIEW_ANIMATING_OVERLAY_H_
// Copyright (c) 2012 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/renderer/webview_animating_overlay.h"
#include "chrome/test/base/chrome_render_view_test.h"
#include "skia/ext/platform_canvas.h"
#include "webkit/glue/webkit_glue.h"
typedef ChromeRenderViewTest WebViewAnimatingOverlayTest;
TEST_F(WebViewAnimatingOverlayTest, ShowHide) {
WebViewAnimatingOverlay overlay(view_);
EXPECT_EQ(overlay.state(), WebViewAnimatingOverlay::HIDDEN);
overlay.Show();
EXPECT_EQ(overlay.state(), WebViewAnimatingOverlay::ANIMATING_IN);
overlay.Hide();
EXPECT_EQ(overlay.state(), WebViewAnimatingOverlay::ANIMATING_OUT);
}
TEST_F(WebViewAnimatingOverlayTest, Paint) {
gfx::Size view_size(100, 100);
Resize(view_size, gfx::Rect(), false);
WebViewAnimatingOverlay overlay(view_);
overlay.Show();
skia::PlatformCanvas canvas;
ASSERT_TRUE(canvas.initialize(view_size.width(), view_size.height(), true));
overlay.paintPageOverlay(webkit_glue::ToWebCanvas(&canvas));
}
......@@ -127,6 +127,10 @@ class CONTENT_EXPORT RenderView : public IPC::Sender {
const WebKit::WebURLRequest& request,
WebKit::WebNavigationPolicy policy) = 0;
// Notifies the renderer that a paint is to be generated for the size
// passed in.
virtual void Repaint(const gfx::Size& size) = 0;
protected:
virtual ~RenderView() {}
};
......
......@@ -309,6 +309,14 @@ uint32 RenderViewTest::GetNavigationIPCType() {
return ViewHostMsg_FrameNavigate::ID;
}
void RenderViewTest::Resize(gfx::Size new_size,
gfx::Rect resizer_rect,
bool is_fullscreen) {
scoped_ptr<IPC::Message> resize_message(new ViewMsg_Resize(
0, new_size, resizer_rect, is_fullscreen));
OnMessageReceived(*resize_message);
}
bool RenderViewTest::OnMessageReceived(const IPC::Message& msg) {
RenderViewImpl* impl = static_cast<RenderViewImpl*>(view_);
return impl->OnMessageReceived(msg);
......
......@@ -110,6 +110,11 @@ class RenderViewTest : public testing::Test {
// Returns the IPC message ID of the navigation message.
uint32 GetNavigationIPCType();
// Resize the view.
void Resize(gfx::Size new_size,
gfx::Rect resizer_rect,
bool is_fullscreen);
// These are all methods from RenderViewImpl that we expose to testing code.
bool OnMessageReceived(const IPC::Message& msg);
void DidNavigateWithinPage(WebKit::WebFrame* frame, bool is_new_navigation);
......
......@@ -2474,6 +2474,10 @@ void RenderViewImpl::loadURLExternally(
loadURLExternally(frame, request, policy, WebString());
}
void RenderViewImpl::Repaint(const gfx::Size& size) {
OnMsgRepaint(size);
}
void RenderViewImpl::loadURLExternally(
WebFrame* frame, const WebURLRequest& request,
WebNavigationPolicy policy,
......
......@@ -711,6 +711,7 @@ class RenderViewImpl : public RenderWidget,
WebKit::WebFrame* frame,
const WebKit::WebURLRequest& request,
WebKit::WebNavigationPolicy policy) OVERRIDE;
virtual void Repaint(const gfx::Size& size) OVERRIDE;
// webkit_glue::WebPluginPageDelegate implementation -------------------------
......
......@@ -143,4 +143,16 @@ TEST_F(AnimationTest, ShouldRenderRichAnimation) {
#endif
}
// Test that current value is always 0 after Start() is called.
TEST_F(AnimationTest, StartState) {
LinearAnimation animation(100, 60, NULL);
EXPECT_EQ(0.0, animation.GetCurrentValue());
animation.Start();
EXPECT_EQ(0.0, animation.GetCurrentValue());
animation.End();
EXPECT_EQ(1.0, animation.GetCurrentValue());
animation.Start();
EXPECT_EQ(0.0, animation.GetCurrentValue());
}
} // namespace ui
......@@ -45,6 +45,14 @@ double LinearAnimation::GetCurrentValue() const {
return state_;
}
void LinearAnimation::SetCurrentValue(double new_value) {
new_value = std::max(0.0, std::min(1.0, new_value));
base::TimeDelta time_delta = base::TimeDelta::FromMicroseconds(
duration_.InMicroseconds() * (new_value - state_));
SetStartTime(start_time() - time_delta);
state_ = new_value;
}
void LinearAnimation::End() {
if (!is_animating())
return;
......@@ -79,6 +87,10 @@ void LinearAnimation::Step(base::TimeTicks time_now) {
Stop();
}
void LinearAnimation::AnimationStarted() {
state_ = 0.0;
}
void LinearAnimation::AnimationStopped() {
if (!in_end_)
return;
......
......@@ -32,6 +32,9 @@ class UI_EXPORT LinearAnimation : public Animation {
// can override this to provide others.
virtual double GetCurrentValue() const OVERRIDE;
// Change the current state of the animation to |new_value|.
void SetCurrentValue(double new_value);
// Skip to the end of the current animation.
void End();
......@@ -42,13 +45,16 @@ class UI_EXPORT LinearAnimation : public Animation {
protected:
// Called when the animation progresses. Subclasses override this to
// efficiently update their state.
virtual void AnimateToState(double state) = 0;
virtual void AnimateToState(double state) {}
// Invoked by the AnimationContainer when the animation is running to advance
// the animation. Use |time_now| rather than Time::Now to avoid multiple
// animations running at the same time diverging.
virtual void Step(base::TimeTicks time_now) OVERRIDE;
// Overriden to initialize state.
virtual void AnimationStarted() OVERRIDE;
// Overriden to advance to the end (if End was invoked).
virtual void AnimationStopped() OVERRIDE;
......
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