From d0c30be6ca4d76dadbac0764c7897affef78541f Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 10 Jun 2015 17:28:43 -0700 Subject: [PATCH] Make the stocks popup menu fade in The final animation is more involved, but this CL starts implementing the menu animation by making it fade in. R=ianh@google.com Review URL: https://codereview.chromium.org/1174253003. --- engine/core/painting/Rect.cpp | 3 ++ .../platform/graphics/GraphicsContext.cpp.rej | 22 ----------- .../platform/graphics/GraphicsContext.h.rej | 15 ------- sdk/lib/framework/components2/popup_menu.dart | 19 +++++---- sdk/lib/framework/fn2.dart | 15 +++++++ sdk/lib/framework/rendering/box.dart | 39 +++++++++++++++++++ 6 files changed, 68 insertions(+), 45 deletions(-) delete mode 100644 engine/platform/graphics/GraphicsContext.cpp.rej delete mode 100644 engine/platform/graphics/GraphicsContext.h.rej diff --git a/engine/core/painting/Rect.cpp b/engine/core/painting/Rect.cpp index ee0bb3cd266..84e8958ad3d 100644 --- a/engine/core/painting/Rect.cpp +++ b/engine/core/painting/Rect.cpp @@ -22,6 +22,9 @@ Rect DartConverter::FromArgumentsWithNullCheck(Dart_NativeArguments args, Dart_Handle dart_rect = Dart_GetNativeArgument(args, index); DCHECK(!LogIfError(dart_rect)); + if (Dart_IsNull(dart_rect)) + return result; + Dart_Handle value = Dart_GetField(dart_rect, DOMDartState::Current()->value_handle()); if (Dart_IsNull(value)) diff --git a/engine/platform/graphics/GraphicsContext.cpp.rej b/engine/platform/graphics/GraphicsContext.cpp.rej deleted file mode 100644 index 8abf473393e..00000000000 --- a/engine/platform/graphics/GraphicsContext.cpp.rej +++ /dev/null @@ -1,22 +0,0 @@ ---- platform/graphics/GraphicsContext.cpp -+++ platform/graphics/GraphicsContext.cpp -@@ -419,19 +419,6 @@ - paint->setLCDRenderText(couldUseLCDRenderedText()); - } - --bool GraphicsContext::couldUseLCDRenderedText() const --{ -- ASSERT(m_canvas); -- // Our layers only have a single alpha channel. This means that subpixel -- // rendered text cannot be composited correctly when the layer is -- // collapsed. Therefore, subpixel text is contextDisabled when we are drawing -- // onto a layer. -- if (contextDisabled() || m_canvas->isDrawingToLayer() || !isCertainlyOpaque()) -- return false; -- -- return shouldSmoothFonts(); --} -- - void GraphicsContext::setCompositeOperation(CompositeOperator compositeOperation, WebBlendMode blendMode) - { - if (contextDisabled()) diff --git a/engine/platform/graphics/GraphicsContext.h.rej b/engine/platform/graphics/GraphicsContext.h.rej deleted file mode 100644 index 291091426b9..00000000000 --- a/engine/platform/graphics/GraphicsContext.h.rej +++ /dev/null @@ -1,15 +0,0 @@ ---- platform/graphics/GraphicsContext.h -+++ platform/graphics/GraphicsContext.h -@@ -155,11 +155,10 @@ - // FIXME: the setter is only used once, at construction time; convert to a constructor param, - // and possibly consolidate with other flags (paintDisabled, isPrinting, ...) - void setShouldSmoothFonts(bool smoothFonts) { m_shouldSmoothFonts = smoothFonts; } -- bool shouldSmoothFonts() const { return m_shouldSmoothFonts; } - - // Turn off LCD text for the paint if not supported on this context. - void adjustTextRenderMode(SkPaint*) const; -- bool couldUseLCDRenderedText() const; -+ bool couldUseLCDRenderedText() const { return m_isCertainlyOpaque && m_shouldSmoothFonts; } - - void setTextDrawingMode(TextDrawingModeFlags mode) { mutableState()->setTextDrawingMode(mode); } - TextDrawingModeFlags textDrawingMode() const { return immutableState()->textDrawingMode(); } diff --git a/sdk/lib/framework/components2/popup_menu.dart b/sdk/lib/framework/components2/popup_menu.dart index d264f575f19..d41f03a82f0 100644 --- a/sdk/lib/framework/components2/popup_menu.dart +++ b/sdk/lib/framework/components2/popup_menu.dart @@ -114,14 +114,17 @@ class PopupMenu extends AnimatedComponent { })); // inlineStyle: _inlineStyle(), - return new ShrinkWrapWidth( - child: new Container( - padding: const EdgeDims.all(8.0), - decoration: new BoxDecoration( - backgroundColor: Grey[50], - borderRadius: 2.0, - boxShadow: Shadow[level]), - child: new Block(children) + return new Opacity( + opacity: math.min(1.0, _position * 3.0), + child: new ShrinkWrapWidth( + child: new Container( + padding: const EdgeDims.all(8.0), + decoration: new BoxDecoration( + backgroundColor: Grey[50], + borderRadius: 2.0, + boxShadow: Shadow[level]), + child: new Block(children) + ) ) ); } diff --git a/sdk/lib/framework/fn2.dart b/sdk/lib/framework/fn2.dart index 32b05ab2a70..227d04cb3db 100644 --- a/sdk/lib/framework/fn2.dart +++ b/sdk/lib/framework/fn2.dart @@ -378,6 +378,21 @@ abstract class OneChildRenderObjectWrapper extends RenderObjectWrapper { } +class Opacity extends OneChildRenderObjectWrapper { + Opacity({ this.opacity, UINode child, Object key }) + : super(child: child, key: key); + + RenderOpacity get root { RenderOpacity result = super.root; return result; } + final double opacity; + + RenderOpacity createNode() => new RenderOpacity(opacity: opacity); + + void syncRenderObject(Opacity old) { + super.syncRenderObject(old); + root.opacity = opacity; + } +} + class ClipRect extends OneChildRenderObjectWrapper { ClipRect({ UINode child, Object key }) diff --git a/sdk/lib/framework/rendering/box.dart b/sdk/lib/framework/rendering/box.dart index 1a38695ccb6..e1a4545cd95 100644 --- a/sdk/lib/framework/rendering/box.dart +++ b/sdk/lib/framework/rendering/box.dart @@ -439,6 +439,45 @@ class RenderShrinkWrapWidth extends RenderProxyBox { } } +class RenderOpacity extends RenderProxyBox { + RenderOpacity({ RenderBox child, double opacity }) + : this._opacity = opacity, super(child) { + assert(opacity >= 0.0 && opacity <= 1.0); + } + + double _opacity; + double get opacity => _opacity; + void set opacity (double value) { + assert(value != null); + assert(value >= 0.0 && value <= 1.0); + if (_opacity == value) + return; + _opacity = value; + markNeedsPaint(); + } + + void paint(RenderObjectDisplayList canvas) { + if (child != null) { + int a = (_opacity * 255).round(); + + if (a == 0) + return; + + if (a == 255) { + child.paint(canvas); + return; + } + + Paint paint = new Paint() + ..color = new Color.fromARGB(a, 0, 0, 0) + ..setTransferMode(sky.TransferMode.srcOverMode); + canvas.saveLayer(null, paint); + child.paint(canvas); + canvas.restore(); + } + } +} + class RenderClipRect extends RenderProxyBox { RenderClipRect({ RenderBox child }) : super(child);