Commit e84ec47c authored by Philip Rogers's avatar Philip Rogers Committed by Commit Bot

Reland: [BGPT] Move link highlights from WebViewImpl to Page

This is a reland of [1] with a fix for animations not starting. This
patch adds a CompositorAnimationHost to LinkHighlights, similar to how
ScrollingCoordinator works, so that the link highlight timeline is
connected to an animation host. A basic test has been added.

[1] https://chromium-review.googlesource.com/c/chromium/src/+/1123315

Link highlights are currently owned by the WebViewImpl so their updates
(creation, deletion, layout, paint) happen entirely outside the main
LocalFrameView update lifecycle. In BlinkGenPropertyTrees we will need
to create foreign layers for link highlights which needs to happen after
the link highlight update (LinkHighlightImpl::UpdateGeometry) but before
blink does the cc update (PaintArtifactCompositor::Update). This patch
moves link highlights from WebViewImpl to Page which will let us manage
their lifecycle from the main blink lifecycle update.

This patch does not fix the issue of link highlights getting painted via
a cc paint callback, which will need to be fixed for SPV2, but this does
move us closer towards that goal.

Bug: 857501
Change-Id: I921594484f7b41844b3e2b49c6ef79458f0e7c5b
Cq-Include-Trybots: luci.chromium.try:linux-blink-gen-property-trees;luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Reviewed-on: https://chromium-review.googlesource.com/1134413Reviewed-by: default avatarTien-Ren Chen <trchen@chromium.org>
Commit-Queue: Philip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575501}
parent 70a3ddd2
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "cc/layers/picture_layer.h" #include "cc/layers/picture_layer.h"
#include "third_party/blink/public/mojom/page/page_visibility_state.mojom-blink.h" #include "third_party/blink/public/mojom/page/page_visibility_state.mojom-blink.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_float_point.h" #include "third_party/blink/public/platform/web_float_point.h"
#include "third_party/blink/public/platform/web_image.h" #include "third_party/blink/public/platform/web_image.h"
#include "third_party/blink/public/platform/web_input_event.h" #include "third_party/blink/public/platform/web_input_event.h"
...@@ -94,6 +93,7 @@ ...@@ -94,6 +93,7 @@
#include "third_party/blink/renderer/core/frame/browser_controls.h" #include "third_party/blink/renderer/core/frame/browser_controls.h"
#include "third_party/blink/renderer/core/frame/event_handler_registry.h" #include "third_party/blink/renderer/core/frame/event_handler_registry.h"
#include "third_party/blink/renderer/core/frame/fullscreen_controller.h" #include "third_party/blink/renderer/core/frame/fullscreen_controller.h"
#include "third_party/blink/renderer/core/frame/link_highlights.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h" #include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h" #include "third_party/blink/renderer/core/frame/local_frame_view.h"
...@@ -139,7 +139,6 @@ ...@@ -139,7 +139,6 @@
#include "third_party/blink/renderer/core/page/validation_message_client_impl.h" #include "third_party/blink/renderer/core/page/validation_message_client_impl.h"
#include "third_party/blink/renderer/core/paint/compositing/paint_layer_compositor.h" #include "third_party/blink/renderer/core/paint/compositing/paint_layer_compositor.h"
#include "third_party/blink/renderer/core/paint/first_meaningful_paint_detector.h" #include "third_party/blink/renderer/core/paint/first_meaningful_paint_detector.h"
#include "third_party/blink/renderer/core/paint/link_highlight_impl.h"
#include "third_party/blink/renderer/core/paint/paint_layer.h" #include "third_party/blink/renderer/core/paint/paint_layer.h"
#include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h" #include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h"
#include "third_party/blink/renderer/core/timing/dom_window_performance.h" #include "third_party/blink/renderer/core/timing/dom_window_performance.h"
...@@ -148,7 +147,6 @@ ...@@ -148,7 +147,6 @@
#include "third_party/blink/renderer/platform/cursor.h" #include "third_party/blink/renderer/platform/cursor.h"
#include "third_party/blink/renderer/platform/fonts/font_cache.h" #include "third_party/blink/renderer/platform/fonts/font_cache.h"
#include "third_party/blink/renderer/platform/geometry/float_rect.h" #include "third_party/blink/renderer/platform/geometry/float_rect.h"
#include "third_party/blink/renderer/platform/graphics/color.h"
#include "third_party/blink/renderer/platform/graphics/compositor_mutator_client.h" #include "third_party/blink/renderer/platform/graphics/compositor_mutator_client.h"
#include "third_party/blink/renderer/platform/graphics/compositor_mutator_impl.h" #include "third_party/blink/renderer/platform/graphics/compositor_mutator_impl.h"
#include "third_party/blink/renderer/platform/graphics/gpu/drawing_buffer.h" #include "third_party/blink/renderer/platform/graphics/gpu/drawing_buffer.h"
...@@ -379,11 +377,6 @@ WebViewImpl::WebViewImpl(WebViewClient* client, ...@@ -379,11 +377,6 @@ WebViewImpl::WebViewImpl(WebViewClient* client,
WebViewImpl::~WebViewImpl() { WebViewImpl::~WebViewImpl() {
DCHECK(!page_); DCHECK(!page_);
// Each highlight uses m_owningWebViewImpl->m_linkHighlightsTimeline
// in destructor. m_linkHighlightsTimeline might be destroyed earlier
// than m_linkHighlights.
DCHECK(link_highlights_.IsEmpty());
} }
ValidationMessageClient* WebViewImpl::GetValidationMessageClient() const { ValidationMessageClient* WebViewImpl::GetValidationMessageClient() const {
...@@ -602,8 +595,7 @@ WebInputEventResult WebViewImpl::HandleGestureEvent( ...@@ -602,8 +595,7 @@ WebInputEventResult WebViewImpl::HandleGestureEvent(
case WebInputEvent::kGestureTapCancel: case WebInputEvent::kGestureTapCancel:
case WebInputEvent::kGestureTap: case WebInputEvent::kGestureTap:
case WebInputEvent::kGestureLongPress: case WebInputEvent::kGestureLongPress:
for (size_t i = 0; i < link_highlights_.size(); ++i) GetPage()->GetLinkHighlights().StartHighlightAnimationIfNeeded();
link_highlights_[i]->StartHighlightAnimationIfNeeded();
break; break;
default: default:
break; break;
...@@ -651,8 +643,7 @@ WebInputEventResult WebViewImpl::HandleGestureEvent( ...@@ -651,8 +643,7 @@ WebInputEventResult WebViewImpl::HandleGestureEvent(
RoundedIntSize(targeted_event.GetHitTestResult().LocalPoint()); RoundedIntSize(targeted_event.GetHitTestResult().LocalPoint());
EnableTapHighlights(highlight_nodes); EnableTapHighlights(highlight_nodes);
for (size_t i = 0; i < link_highlights_.size(); ++i) GetPage()->GetLinkHighlights().StartHighlightAnimationIfNeeded();
link_highlights_[i]->StartHighlightAnimationIfNeeded();
event_result = WebInputEventResult::kHandledSystem; event_result = WebInputEventResult::kHandledSystem;
event_cancelled = true; event_cancelled = true;
break; break;
...@@ -1245,30 +1236,7 @@ void WebViewImpl::EnableTapHighlightAtPoint( ...@@ -1245,30 +1236,7 @@ void WebViewImpl::EnableTapHighlightAtPoint(
void WebViewImpl::EnableTapHighlights( void WebViewImpl::EnableTapHighlights(
HeapVector<Member<Node>>& highlight_nodes) { HeapVector<Member<Node>>& highlight_nodes) {
if (highlight_nodes.IsEmpty()) GetPage()->GetLinkHighlights().SetTapHighlights(highlight_nodes);
return;
// Always clear any existing highlight when this is invoked, even if we
// don't get a new target to highlight.
link_highlights_.clear();
for (size_t i = 0; i < highlight_nodes.size(); ++i) {
Node* node = highlight_nodes[i];
if (!node || !node->GetLayoutObject())
continue;
Color highlight_color =
node->GetLayoutObject()->Style()->TapHighlightColor();
// Safari documentation for -webkit-tap-highlight-color says if the
// specified color has 0 alpha, then tap highlighting is disabled.
// http://developer.apple.com/library/safari/#documentation/appleapplications/reference/safaricssref/articles/standardcssproperties.html
if (!highlight_color.Alpha())
continue;
link_highlights_.push_back(LinkHighlightImpl::Create(node, this));
}
UpdateAllLifecyclePhases(); UpdateAllLifecyclePhases();
} }
...@@ -1766,8 +1734,8 @@ void WebViewImpl::UpdateLifecycle(LifecycleUpdate requested_update) { ...@@ -1766,8 +1734,8 @@ void WebViewImpl::UpdateLifecycle(LifecycleUpdate requested_update) {
// TODO(chrishtr): link highlights don't currently paint themselves, it's // TODO(chrishtr): link highlights don't currently paint themselves, it's
// still driven by cc. Fix this. // still driven by cc. Fix this.
for (size_t i = 0; i < link_highlights_.size(); ++i) // TODO(pdr): Move this to LocalFrameView::UpdateLifecyclePhasesInternal.
link_highlights_[i]->UpdateGeometry(); GetPage()->GetLinkHighlights().UpdateGeometry();
if (LocalFrameView* view = MainFrameImpl()->GetFrameView()) { if (LocalFrameView* view = MainFrameImpl()->GetFrameView()) {
LocalFrame* frame = MainFrameImpl()->GetFrame(); LocalFrame* frame = MainFrameImpl()->GetFrame();
...@@ -2118,12 +2086,6 @@ bool WebViewImpl::IsAcceleratedCompositingActive() const { ...@@ -2118,12 +2086,6 @@ bool WebViewImpl::IsAcceleratedCompositingActive() const {
} }
void WebViewImpl::WillCloseLayerTreeView() { void WebViewImpl::WillCloseLayerTreeView() {
if (link_highlights_timeline_) {
link_highlights_.clear();
DetachCompositorAnimationTimeline(link_highlights_timeline_.get());
link_highlights_timeline_.reset();
}
if (layer_tree_view_) if (layer_tree_view_)
GetPage()->WillCloseLayerTreeView(*layer_tree_view_, nullptr); GetPage()->WillCloseLayerTreeView(*layer_tree_view_, nullptr);
...@@ -3157,7 +3119,8 @@ void WebViewImpl::DidCommitLoad(bool is_new_navigation, ...@@ -3157,7 +3119,8 @@ void WebViewImpl::DidCommitLoad(bool is_new_navigation,
GetPage()->GetVisualViewport().MainFrameDidChangeSize(); GetPage()->GetVisualViewport().MainFrameDidChangeSize();
// Make sure link highlight from previous page is cleared. // Make sure link highlight from previous page is cleared.
link_highlights_.clear(); // TODO(pdr): Move this to Page::DidCommitLoad.
GetPage()->GetLinkHighlights().ResetForPageNavigation();
if (!MainFrameImpl()) if (!MainFrameImpl())
return; return;
} }
...@@ -3448,18 +3411,6 @@ void WebViewImpl::ScheduleAnimationForWidget() { ...@@ -3448,18 +3411,6 @@ void WebViewImpl::ScheduleAnimationForWidget() {
client_->WidgetClient()->ScheduleAnimation(); client_->WidgetClient()->ScheduleAnimation();
} }
void WebViewImpl::AttachCompositorAnimationTimeline(
CompositorAnimationTimeline* timeline) {
if (animation_host_)
animation_host_->AddTimeline(*timeline);
}
void WebViewImpl::DetachCompositorAnimationTimeline(
CompositorAnimationTimeline* timeline) {
if (animation_host_)
animation_host_->RemoveTimeline(*timeline);
}
void WebViewImpl::InitializeLayerTreeView() { void WebViewImpl::InitializeLayerTreeView() {
if (client_) { if (client_) {
layer_tree_view_ = client_->InitializeLayerTreeView(); layer_tree_view_ = client_->InitializeLayerTreeView();
...@@ -3485,11 +3436,6 @@ void WebViewImpl::InitializeLayerTreeView() { ...@@ -3485,11 +3436,6 @@ void WebViewImpl::InitializeLayerTreeView() {
// hit this code and then delete allowsBrokenNullLayerTreeView. // hit this code and then delete allowsBrokenNullLayerTreeView.
DCHECK(layer_tree_view_ || !client_ || DCHECK(layer_tree_view_ || !client_ ||
client_->WidgetClient()->AllowsBrokenNullLayerTreeView()); client_->WidgetClient()->AllowsBrokenNullLayerTreeView());
if (Platform::Current()->IsThreadedAnimationEnabled() && layer_tree_view_) {
link_highlights_timeline_ = CompositorAnimationTimeline::Create();
AttachCompositorAnimationTimeline(link_highlights_timeline_.get());
}
} }
void WebViewImpl::ApplyViewportDeltas( void WebViewImpl::ApplyViewportDeltas(
......
...@@ -56,7 +56,6 @@ ...@@ -56,7 +56,6 @@
#include "third_party/blink/renderer/core/page/event_with_hit_test_results.h" #include "third_party/blink/renderer/core/page/event_with_hit_test_results.h"
#include "third_party/blink/renderer/core/page/page_widget_delegate.h" #include "third_party/blink/renderer/core/page/page_widget_delegate.h"
#include "third_party/blink/renderer/core/page/scoped_page_pauser.h" #include "third_party/blink/renderer/core/page/scoped_page_pauser.h"
#include "third_party/blink/renderer/platform/animation/compositor_animation_timeline.h"
#include "third_party/blink/renderer/platform/geometry/int_point.h" #include "third_party/blink/renderer/platform/geometry/int_point.h"
#include "third_party/blink/renderer/platform/geometry/int_rect.h" #include "third_party/blink/renderer/platform/geometry/int_rect.h"
#include "third_party/blink/renderer/platform/graphics/graphics_layer.h" #include "third_party/blink/renderer/platform/graphics/graphics_layer.h"
...@@ -78,7 +77,6 @@ class CompositorAnimationHost; ...@@ -78,7 +77,6 @@ class CompositorAnimationHost;
class DevToolsEmulator; class DevToolsEmulator;
class Frame; class Frame;
class FullscreenController; class FullscreenController;
class LinkHighlightImpl;
class PageOverlay; class PageOverlay;
class PageScaleConstraintsSet; class PageScaleConstraintsSet;
class PaintLayerCompositor; class PaintLayerCompositor;
...@@ -340,9 +338,6 @@ class CORE_EXPORT WebViewImpl final : public WebView, ...@@ -340,9 +338,6 @@ class CORE_EXPORT WebViewImpl final : public WebView,
GraphicsLayer* RootGraphicsLayer(); GraphicsLayer* RootGraphicsLayer();
void RegisterViewportLayersWithCompositor(); void RegisterViewportLayersWithCompositor();
PaintLayerCompositor* Compositor() const; PaintLayerCompositor* Compositor() const;
CompositorAnimationTimeline* LinkHighlightsTimeline() const {
return link_highlights_timeline_.get();
}
PageScheduler* Scheduler() const override; PageScheduler* Scheduler() const override;
void SetVisibilityState(mojom::PageVisibilityState, bool) override; void SetVisibilityState(mojom::PageVisibilityState, bool) override;
...@@ -397,12 +392,6 @@ class CORE_EXPORT WebViewImpl final : public WebView, ...@@ -397,12 +392,6 @@ class CORE_EXPORT WebViewImpl final : public WebView,
bool HasHorizontalScrollbar(); bool HasHorizontalScrollbar();
bool HasVerticalScrollbar(); bool HasVerticalScrollbar();
// Exposed for tests.
unsigned NumLinkHighlights() { return link_highlights_.size(); }
LinkHighlightImpl* GetLinkHighlight(int i) {
return link_highlights_[i].get();
}
WebSettingsImpl* SettingsImpl(); WebSettingsImpl* SettingsImpl();
// Returns the bounding box of the block type node touched by the WebPoint. // Returns the bounding box of the block type node touched by the WebPoint.
...@@ -540,8 +529,6 @@ class CORE_EXPORT WebViewImpl final : public WebView, ...@@ -540,8 +529,6 @@ class CORE_EXPORT WebViewImpl final : public WebView,
void SetRootGraphicsLayer(GraphicsLayer*); void SetRootGraphicsLayer(GraphicsLayer*);
void SetRootLayer(scoped_refptr<cc::Layer>); void SetRootLayer(scoped_refptr<cc::Layer>);
void AttachCompositorAnimationTimeline(CompositorAnimationTimeline*);
void DetachCompositorAnimationTimeline(CompositorAnimationTimeline*);
LocalFrame* FocusedLocalFrameInWidget() const; LocalFrame* FocusedLocalFrameInWidget() const;
LocalFrame* FocusedLocalFrameAvailableForIme() const; LocalFrame* FocusedLocalFrameAvailableForIme() const;
...@@ -652,8 +639,6 @@ class CORE_EXPORT WebViewImpl final : public WebView, ...@@ -652,8 +639,6 @@ class CORE_EXPORT WebViewImpl final : public WebView,
GraphicsLayer* visual_viewport_container_layer_; GraphicsLayer* visual_viewport_container_layer_;
bool matches_heuristics_for_gpu_rasterization_; bool matches_heuristics_for_gpu_rasterization_;
Vector<std::unique_ptr<LinkHighlightImpl>> link_highlights_;
std::unique_ptr<CompositorAnimationTimeline> link_highlights_timeline_;
std::unique_ptr<FullscreenController> fullscreen_controller_; std::unique_ptr<FullscreenController> fullscreen_controller_;
WebPoint last_tap_disambiguation_best_candidate_position_; WebPoint last_tap_disambiguation_best_candidate_position_;
......
...@@ -78,6 +78,8 @@ blink_core_sources("frame") { ...@@ -78,6 +78,8 @@ blink_core_sources("frame") {
"intervention_report_body.h", "intervention_report_body.h",
"layout_subtree_root_list.cc", "layout_subtree_root_list.cc",
"layout_subtree_root_list.h", "layout_subtree_root_list.h",
"link_highlights.cc",
"link_highlights.h",
"local_dom_window.cc", "local_dom_window.cc",
"local_dom_window.h", "local_dom_window.h",
"local_frame.cc", "local_frame.cc",
......
// Copyright 2018 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 "third_party/blink/renderer/core/frame/link_highlights.h"
#include <memory>
#include "cc/layers/picture_layer.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/public/platform/web_layer_tree_view.h"
#include "third_party/blink/renderer/core/dom/node.h"
#include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/page/chrome_client.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/paint/link_highlight_impl.h"
#include "third_party/blink/renderer/platform/animation/compositor_animation_host.h"
#include "third_party/blink/renderer/platform/animation/compositor_animation_timeline.h"
namespace blink {
LinkHighlights::LinkHighlights(Page& owner) : page_(&owner) {}
LinkHighlights::~LinkHighlights() {
RemoveAllHighlights();
}
void LinkHighlights::Trace(blink::Visitor* visitor) {
visitor->Trace(page_);
}
void LinkHighlights::RemoveAllHighlights() {
if (timeline_) {
for (auto& highlight : link_highlights_)
timeline_->AnimationDestroyed(*highlight);
}
link_highlights_.clear();
}
void LinkHighlights::ResetForPageNavigation() {
RemoveAllHighlights();
}
void LinkHighlights::SetTapHighlights(
HeapVector<Member<Node>>& highlight_nodes) {
// Always clear any existing highlight when this is invoked, even if we
// don't get a new target to highlight.
RemoveAllHighlights();
for (size_t i = 0; i < highlight_nodes.size(); ++i) {
Node* node = highlight_nodes[i];
if (!node || !node->GetLayoutObject())
continue;
Color highlight_color =
node->GetLayoutObject()->Style()->TapHighlightColor();
// Safari documentation for -webkit-tap-highlight-color says if the
// specified color has 0 alpha, then tap highlighting is disabled.
// http://developer.apple.com/library/safari/#documentation/appleapplications/reference/safaricssref/articles/standardcssproperties.html
if (!highlight_color.Alpha())
continue;
link_highlights_.push_back(LinkHighlightImpl::Create(node));
if (timeline_)
timeline_->AnimationAttached(*link_highlights_.back());
}
}
void LinkHighlights::UpdateGeometry() {
for (auto& highlight : link_highlights_)
highlight->UpdateGeometry();
}
LocalFrame* LinkHighlights::MainFrame() const {
return GetPage().MainFrame() && GetPage().MainFrame()->IsLocalFrame()
? GetPage().DeprecatedLocalMainFrame()
: nullptr;
}
void LinkHighlights::StartHighlightAnimationIfNeeded() {
for (auto& highlight : link_highlights_)
highlight->StartHighlightAnimationIfNeeded();
if (auto* local_frame = MainFrame())
GetPage().GetChromeClient().ScheduleAnimation(local_frame->View());
}
void LinkHighlights::LayerTreeViewInitialized(
WebLayerTreeView& layer_tree_view) {
if (Platform::Current()->IsThreadedAnimationEnabled()) {
timeline_ = CompositorAnimationTimeline::Create();
animation_host_ = std::make_unique<CompositorAnimationHost>(
layer_tree_view.CompositorAnimationHost());
animation_host_->AddTimeline(*timeline_);
}
}
void LinkHighlights::WillCloseLayerTreeView(WebLayerTreeView& layer_tree_view) {
RemoveAllHighlights();
if (timeline_) {
animation_host_->RemoveTimeline(*timeline_);
timeline_.reset();
}
animation_host_ = nullptr;
}
} // namespace blink
// Copyright 2018 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 THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_LINK_HIGHLIGHTS_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_LINK_HIGHLIGHTS_H_
#include <memory>
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
namespace blink {
class Page;
class LinkHighlightImpl;
class CompositorAnimationHost;
class CompositorAnimationTimeline;
class WebLayerTreeView;
class LocalFrame;
class CORE_EXPORT LinkHighlights final
: public GarbageCollectedFinalized<LinkHighlights> {
public:
static LinkHighlights* Create(Page& page) { return new LinkHighlights(page); }
virtual ~LinkHighlights();
virtual void Trace(blink::Visitor*);
void ResetForPageNavigation();
void SetTapHighlights(HeapVector<Member<Node>>&);
void UpdateGeometry();
void StartHighlightAnimationIfNeeded();
void LayerTreeViewInitialized(WebLayerTreeView&);
void WillCloseLayerTreeView(WebLayerTreeView&);
private:
FRIEND_TEST_ALL_PREFIXES(LinkHighlightImplTest, verifyWebViewImplIntegration);
FRIEND_TEST_ALL_PREFIXES(LinkHighlightImplTest, resetDuringNodeRemoval);
FRIEND_TEST_ALL_PREFIXES(LinkHighlightImplTest, resetLayerTreeView);
FRIEND_TEST_ALL_PREFIXES(LinkHighlightImplTest, multipleHighlights);
explicit LinkHighlights(Page&);
void RemoveAllHighlights();
LocalFrame* MainFrame() const;
Page& GetPage() const {
DCHECK(page_);
return *page_;
}
Member<Page> page_;
Vector<std::unique_ptr<LinkHighlightImpl>> link_highlights_;
std::unique_ptr<CompositorAnimationHost> animation_host_;
std::unique_ptr<CompositorAnimationTimeline> timeline_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_LINK_HIGHLIGHTS_H_
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "third_party/blink/renderer/core/frame/dom_timer.h" #include "third_party/blink/renderer/core/frame/dom_timer.h"
#include "third_party/blink/renderer/core/frame/event_handler_registry.h" #include "third_party/blink/renderer/core/frame/event_handler_registry.h"
#include "third_party/blink/renderer/core/frame/frame_console.h" #include "third_party/blink/renderer/core/frame/frame_console.h"
#include "third_party/blink/renderer/core/frame/link_highlights.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h" #include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h" #include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/page_scale_constraints.h" #include "third_party/blink/renderer/core/frame/page_scale_constraints.h"
...@@ -162,6 +163,7 @@ Page::Page(PageClients& page_clients) ...@@ -162,6 +163,7 @@ Page::Page(PageClients& page_clients)
visual_viewport_(VisualViewport::Create(*this)), visual_viewport_(VisualViewport::Create(*this)),
overscroll_controller_( overscroll_controller_(
OverscrollController::Create(GetVisualViewport(), GetChromeClient())), OverscrollController::Create(GetVisualViewport(), GetChromeClient())),
link_highlights_(LinkHighlights::Create(*this)),
plugin_data_(nullptr), plugin_data_(nullptr),
opened_by_dom_(false), opened_by_dom_(false),
tab_key_cycles_through_elements_(true), tab_key_cycles_through_elements_(true),
...@@ -262,6 +264,10 @@ const OverscrollController& Page::GetOverscrollController() const { ...@@ -262,6 +264,10 @@ const OverscrollController& Page::GetOverscrollController() const {
return *overscroll_controller_; return *overscroll_controller_;
} }
LinkHighlights& Page::GetLinkHighlights() {
return *link_highlights_;
}
DOMRectList* Page::NonFastScrollableRectsForTesting(const LocalFrame* frame) { DOMRectList* Page::NonFastScrollableRectsForTesting(const LocalFrame* frame) {
// Update lifecycle to kPrePaintClean. This includes the compositing update // Update lifecycle to kPrePaintClean. This includes the compositing update
// and ScrollingCoordinator::UpdateAfterPaint, which computes the non-fast // and ScrollingCoordinator::UpdateAfterPaint, which computes the non-fast
...@@ -725,6 +731,7 @@ void Page::Trace(blink::Visitor* visitor) { ...@@ -725,6 +731,7 @@ void Page::Trace(blink::Visitor* visitor) {
visitor->Trace(global_root_scroller_controller_); visitor->Trace(global_root_scroller_controller_);
visitor->Trace(visual_viewport_); visitor->Trace(visual_viewport_);
visitor->Trace(overscroll_controller_); visitor->Trace(overscroll_controller_);
visitor->Trace(link_highlights_);
visitor->Trace(main_frame_); visitor->Trace(main_frame_);
visitor->Trace(plugin_data_); visitor->Trace(plugin_data_);
visitor->Trace(validation_message_client_); visitor->Trace(validation_message_client_);
...@@ -739,12 +746,14 @@ void Page::LayerTreeViewInitialized(WebLayerTreeView& layer_tree_view, ...@@ -739,12 +746,14 @@ void Page::LayerTreeViewInitialized(WebLayerTreeView& layer_tree_view,
LocalFrameView* view) { LocalFrameView* view) {
if (GetScrollingCoordinator()) if (GetScrollingCoordinator())
GetScrollingCoordinator()->LayerTreeViewInitialized(layer_tree_view, view); GetScrollingCoordinator()->LayerTreeViewInitialized(layer_tree_view, view);
GetLinkHighlights().LayerTreeViewInitialized(layer_tree_view);
} }
void Page::WillCloseLayerTreeView(WebLayerTreeView& layer_tree_view, void Page::WillCloseLayerTreeView(WebLayerTreeView& layer_tree_view,
LocalFrameView* view) { LocalFrameView* view) {
if (scrolling_coordinator_) if (scrolling_coordinator_)
scrolling_coordinator_->WillCloseLayerTreeView(layer_tree_view, view); scrolling_coordinator_->WillCloseLayerTreeView(layer_tree_view, view);
GetLinkHighlights().WillCloseLayerTreeView(layer_tree_view);
} }
void Page::WillBeDestroyed() { void Page::WillBeDestroyed() {
......
...@@ -59,6 +59,7 @@ class DragCaret; ...@@ -59,6 +59,7 @@ class DragCaret;
class DragController; class DragController;
class FocusController; class FocusController;
class Frame; class Frame;
class LinkHighlights;
class OverscrollController; class OverscrollController;
struct PageScaleConstraints; struct PageScaleConstraints;
class PageScaleConstraintsSet; class PageScaleConstraintsSet;
...@@ -216,6 +217,8 @@ class CORE_EXPORT Page final : public GarbageCollectedFinalized<Page>, ...@@ -216,6 +217,8 @@ class CORE_EXPORT Page final : public GarbageCollectedFinalized<Page>,
VisualViewport& GetVisualViewport(); VisualViewport& GetVisualViewport();
const VisualViewport& GetVisualViewport() const; const VisualViewport& GetVisualViewport() const;
LinkHighlights& GetLinkHighlights();
OverscrollController& GetOverscrollController(); OverscrollController& GetOverscrollController();
const OverscrollController& GetOverscrollController() const; const OverscrollController& GetOverscrollController() const;
...@@ -363,6 +366,7 @@ class CORE_EXPORT Page final : public GarbageCollectedFinalized<Page>, ...@@ -363,6 +366,7 @@ class CORE_EXPORT Page final : public GarbageCollectedFinalized<Page>,
global_root_scroller_controller_; global_root_scroller_controller_;
const Member<VisualViewport> visual_viewport_; const Member<VisualViewport> visual_viewport_;
const Member<OverscrollController> overscroll_controller_; const Member<OverscrollController> overscroll_controller_;
const Member<LinkHighlights> link_highlights_;
Member<PluginData> plugin_data_; Member<PluginData> plugin_data_;
......
...@@ -38,10 +38,10 @@ ...@@ -38,10 +38,10 @@
#include "third_party/blink/public/web/blink.h" #include "third_party/blink/public/web/blink.h"
#include "third_party/blink/renderer/core/dom/layout_tree_builder_traversal.h" #include "third_party/blink/renderer/core/dom/layout_tree_builder_traversal.h"
#include "third_party/blink/renderer/core/dom/node.h" #include "third_party/blink/renderer/core/dom/node.h"
#include "third_party/blink/renderer/core/exported/web_settings_impl.h"
#include "third_party/blink/renderer/core/exported/web_view_impl.h" #include "third_party/blink/renderer/core/exported/web_view_impl.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h" #include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/frame/web_frame_widget_base.h" #include "third_party/blink/renderer/core/frame/web_frame_widget_base.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h" #include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/core/layout/layout_box_model_object.h" #include "third_party/blink/renderer/core/layout/layout_box_model_object.h"
...@@ -68,15 +68,12 @@ ...@@ -68,15 +68,12 @@
namespace blink { namespace blink {
std::unique_ptr<LinkHighlightImpl> LinkHighlightImpl::Create( std::unique_ptr<LinkHighlightImpl> LinkHighlightImpl::Create(Node* node) {
Node* node, return base::WrapUnique(new LinkHighlightImpl(node));
WebViewImpl* owning_web_view) {
return base::WrapUnique(new LinkHighlightImpl(node, owning_web_view));
} }
LinkHighlightImpl::LinkHighlightImpl(Node* node, WebViewImpl* owning_web_view) LinkHighlightImpl::LinkHighlightImpl(Node* node)
: node_(node), : node_(node),
owning_web_view_(owning_web_view),
current_graphics_layer_(nullptr), current_graphics_layer_(nullptr),
is_scrolling_graphics_layer_(false), is_scrolling_graphics_layer_(false),
geometry_needs_update_(false), geometry_needs_update_(false),
...@@ -84,15 +81,12 @@ LinkHighlightImpl::LinkHighlightImpl(Node* node, WebViewImpl* owning_web_view) ...@@ -84,15 +81,12 @@ LinkHighlightImpl::LinkHighlightImpl(Node* node, WebViewImpl* owning_web_view)
start_time_(CurrentTimeTicks()), start_time_(CurrentTimeTicks()),
unique_id_(NewUniqueObjectId()) { unique_id_(NewUniqueObjectId()) {
DCHECK(node_); DCHECK(node_);
DCHECK(owning_web_view);
content_layer_ = cc::PictureLayer::Create(this); content_layer_ = cc::PictureLayer::Create(this);
content_layer_->SetTransformOrigin(FloatPoint3D()); content_layer_->SetTransformOrigin(FloatPoint3D());
compositor_animation_ = CompositorAnimation::Create(); compositor_animation_ = CompositorAnimation::Create();
DCHECK(compositor_animation_); DCHECK(compositor_animation_);
compositor_animation_->SetAnimationDelegate(this); compositor_animation_->SetAnimationDelegate(this);
if (owning_web_view_->LinkHighlightsTimeline())
owning_web_view_->LinkHighlightsTimeline()->AnimationAttached(*this);
CompositorElementId element_id = CompositorElementId element_id =
CompositorElementIdFromUniqueObjectId(unique_id_); CompositorElementIdFromUniqueObjectId(unique_id_);
...@@ -106,8 +100,6 @@ LinkHighlightImpl::LinkHighlightImpl(Node* node, WebViewImpl* owning_web_view) ...@@ -106,8 +100,6 @@ LinkHighlightImpl::LinkHighlightImpl(Node* node, WebViewImpl* owning_web_view)
LinkHighlightImpl::~LinkHighlightImpl() { LinkHighlightImpl::~LinkHighlightImpl() {
if (compositor_animation_->IsElementAttached()) if (compositor_animation_->IsElementAttached())
compositor_animation_->DetachElement(); compositor_animation_->DetachElement();
if (owning_web_view_->LinkHighlightsTimeline())
owning_web_view_->LinkHighlightsTimeline()->AnimationDestroyed(*this);
compositor_animation_->SetAnimationDelegate(nullptr); compositor_animation_->SetAnimationDelegate(nullptr);
compositor_animation_.reset(); compositor_animation_.reset();
...@@ -228,7 +220,9 @@ bool LinkHighlightImpl::ComputeHighlightLayerPathAndPosition( ...@@ -228,7 +220,9 @@ bool LinkHighlightImpl::ComputeHighlightLayerPathAndPosition(
// links: these should ideally be merged into a single rect before creating // links: these should ideally be merged into a single rect before creating
// the path, but that's another CL. // the path, but that's another CL.
if (quads.size() == 1 && transformed_quad.IsRectilinear() && if (quads.size() == 1 && transformed_quad.IsRectilinear() &&
!owning_web_view_->SettingsImpl()->MockGestureTapHighlightsEnabled()) { !node_->GetDocument()
.GetSettings()
->GetMockGestureTapHighlightsEnabled()) {
FloatSize rect_rounding_radii(3, 3); FloatSize rect_rounding_radii(3, 3);
new_path.AddRoundedRect(transformed_quad.BoundingBox(), new_path.AddRoundedRect(transformed_quad.BoundingBox(),
rect_rounding_radii); rect_rounding_radii);
...@@ -326,7 +320,6 @@ void LinkHighlightImpl::StartHighlightAnimationIfNeeded() { ...@@ -326,7 +320,6 @@ void LinkHighlightImpl::StartHighlightAnimationIfNeeded() {
compositor_animation_->AddKeyframeModel(std::move(keyframe_model)); compositor_animation_->AddKeyframeModel(std::move(keyframe_model));
Invalidate(); Invalidate();
owning_web_view_->MainFrameImpl()->FrameWidgetImpl()->ScheduleAnimation();
} }
void LinkHighlightImpl::ClearGraphicsLayerLinkHighlightPointer() { void LinkHighlightImpl::ClearGraphicsLayerLinkHighlightPointer() {
......
...@@ -50,14 +50,13 @@ namespace blink { ...@@ -50,14 +50,13 @@ namespace blink {
class GraphicsLayer; class GraphicsLayer;
class LayoutBoxModelObject; class LayoutBoxModelObject;
class Node; class Node;
class WebViewImpl;
class CORE_EXPORT LinkHighlightImpl final : public LinkHighlight, class CORE_EXPORT LinkHighlightImpl final : public LinkHighlight,
public cc::ContentLayerClient, public cc::ContentLayerClient,
public CompositorAnimationDelegate, public CompositorAnimationDelegate,
public CompositorAnimationClient { public CompositorAnimationClient {
public: public:
static std::unique_ptr<LinkHighlightImpl> Create(Node*, WebViewImpl*); static std::unique_ptr<LinkHighlightImpl> Create(Node*);
~LinkHighlightImpl() override; ~LinkHighlightImpl() override;
void StartHighlightAnimationIfNeeded(); void StartHighlightAnimationIfNeeded();
...@@ -88,7 +87,7 @@ class CORE_EXPORT LinkHighlightImpl final : public LinkHighlight, ...@@ -88,7 +87,7 @@ class CORE_EXPORT LinkHighlightImpl final : public LinkHighlight,
} }
private: private:
LinkHighlightImpl(Node*, WebViewImpl*); LinkHighlightImpl(Node*);
void ReleaseResources(); void ReleaseResources();
void ComputeQuads(const Node&, Vector<FloatQuad>&) const; void ComputeQuads(const Node&, Vector<FloatQuad>&) const;
...@@ -104,7 +103,6 @@ class CORE_EXPORT LinkHighlightImpl final : public LinkHighlight, ...@@ -104,7 +103,6 @@ class CORE_EXPORT LinkHighlightImpl final : public LinkHighlight,
Path path_; Path path_;
Persistent<Node> node_; Persistent<Node> node_;
WebViewImpl* owning_web_view_;
GraphicsLayer* current_graphics_layer_; GraphicsLayer* current_graphics_layer_;
bool is_scrolling_graphics_layer_; bool is_scrolling_graphics_layer_;
std::unique_ptr<CompositorAnimation> compositor_animation_; std::unique_ptr<CompositorAnimation> compositor_animation_;
......
...@@ -40,11 +40,13 @@ ...@@ -40,11 +40,13 @@
#include "third_party/blink/renderer/core/events/web_input_event_conversion.h" #include "third_party/blink/renderer/core/events/web_input_event_conversion.h"
#include "third_party/blink/renderer/core/exported/web_view_impl.h" #include "third_party/blink/renderer/core/exported/web_view_impl.h"
#include "third_party/blink/renderer/core/frame/frame_test_helpers.h" #include "third_party/blink/renderer/core/frame/frame_test_helpers.h"
#include "third_party/blink/renderer/core/frame/link_highlights.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h" #include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/web_local_frame_impl.h" #include "third_party/blink/renderer/core/frame/web_local_frame_impl.h"
#include "third_party/blink/renderer/core/input/event_handler.h" #include "third_party/blink/renderer/core/input/event_handler.h"
#include "third_party/blink/renderer/core/page/page.h" #include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/page/touch_disambiguation.h" #include "third_party/blink/renderer/core/page/touch_disambiguation.h"
#include "third_party/blink/renderer/platform/animation/compositor_animation_timeline.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/geometry/int_rect.h" #include "third_party/blink/renderer/platform/geometry/int_rect.h"
#include "third_party/blink/renderer/platform/graphics/graphics_layer.h" #include "third_party/blink/renderer/platform/graphics/graphics_layer.h"
...@@ -104,26 +106,34 @@ TEST(LinkHighlightImplTest, verifyWebViewImplIntegration) { ...@@ -104,26 +106,34 @@ TEST(LinkHighlightImplTest, verifyWebViewImplIntegration) {
web_view_impl->EnableTapHighlightAtPoint( web_view_impl->EnableTapHighlightAtPoint(
GetTargetedEvent(web_view_impl, touch_event)); GetTargetedEvent(web_view_impl, touch_event));
EXPECT_TRUE(web_view_impl->GetLinkHighlight(0)); const auto& highlights =
EXPECT_TRUE(web_view_impl->GetLinkHighlight(0)->Layer()); web_view_impl->GetPage()->GetLinkHighlights().link_highlights_;
EXPECT_TRUE(highlights.at(0));
EXPECT_TRUE(highlights.at(0)->Layer());
// Find a target inside a scrollable div // Find a target inside a scrollable div
touch_event.SetPositionInWidget(WebFloatPoint(20, 100)); touch_event.SetPositionInWidget(WebFloatPoint(20, 100));
web_view_impl->EnableTapHighlightAtPoint( web_view_impl->EnableTapHighlightAtPoint(
GetTargetedEvent(web_view_impl, touch_event)); GetTargetedEvent(web_view_impl, touch_event));
ASSERT_TRUE(web_view_impl->GetLinkHighlight(0)); ASSERT_TRUE(highlights.at(0));
// Enesure the timeline was added to a host.
EXPECT_TRUE(!!web_view_impl->GetPage()
->GetLinkHighlights()
.timeline_->GetAnimationTimeline()
->animation_host());
// Don't highlight if no "hand cursor" // Don't highlight if no "hand cursor"
touch_event.SetPositionInWidget( touch_event.SetPositionInWidget(
WebFloatPoint(20, 220)); // An A-link with cross-hair cursor. WebFloatPoint(20, 220)); // An A-link with cross-hair cursor.
web_view_impl->EnableTapHighlightAtPoint( web_view_impl->EnableTapHighlightAtPoint(
GetTargetedEvent(web_view_impl, touch_event)); GetTargetedEvent(web_view_impl, touch_event));
ASSERT_EQ(0U, web_view_impl->NumLinkHighlights()); ASSERT_EQ(0U, highlights.size());
touch_event.SetPositionInWidget(WebFloatPoint(20, 260)); // A text input box. touch_event.SetPositionInWidget(WebFloatPoint(20, 260)); // A text input box.
web_view_impl->EnableTapHighlightAtPoint( web_view_impl->EnableTapHighlightAtPoint(
GetTargetedEvent(web_view_impl, touch_event)); GetTargetedEvent(web_view_impl, touch_event));
ASSERT_EQ(0U, web_view_impl->NumLinkHighlights()); ASSERT_EQ(0U, highlights.size());
Platform::Current() Platform::Current()
->GetURLLoaderMockFactory() ->GetURLLoaderMockFactory()
...@@ -152,16 +162,17 @@ TEST(LinkHighlightImplTest, resetDuringNodeRemoval) { ...@@ -152,16 +162,17 @@ TEST(LinkHighlightImplTest, resetDuringNodeRemoval) {
ASSERT_TRUE(touch_node); ASSERT_TRUE(touch_node);
web_view_impl->EnableTapHighlightAtPoint(targeted_event); web_view_impl->EnableTapHighlightAtPoint(targeted_event);
ASSERT_TRUE(web_view_impl->GetLinkHighlight(0)); const auto& highlights = web_view_impl->GetPage()->GetLinkHighlights();
ASSERT_TRUE(highlights.link_highlights_.at(0));
GraphicsLayer* highlight_layer = GraphicsLayer* highlight_layer =
web_view_impl->GetLinkHighlight(0)->CurrentGraphicsLayerForTesting(); highlights.link_highlights_.at(0)->CurrentGraphicsLayerForTesting();
ASSERT_TRUE(highlight_layer); ASSERT_TRUE(highlight_layer);
EXPECT_TRUE(highlight_layer->GetLinkHighlight(0)); EXPECT_TRUE(highlight_layer->GetLinkHighlight(0));
touch_node->remove(IGNORE_EXCEPTION_FOR_TESTING); touch_node->remove(IGNORE_EXCEPTION_FOR_TESTING);
web_view_impl->UpdateAllLifecyclePhases(); web_view_impl->UpdateAllLifecyclePhases();
ASSERT_EQ(0U, highlight_layer->NumLinkHighlights()); EXPECT_EQ(0U, highlight_layer->NumLinkHighlights());
Platform::Current() Platform::Current()
->GetURLLoaderMockFactory() ->GetURLLoaderMockFactory()
...@@ -191,10 +202,12 @@ TEST(LinkHighlightImplTest, resetLayerTreeView) { ...@@ -191,10 +202,12 @@ TEST(LinkHighlightImplTest, resetLayerTreeView) {
ASSERT_TRUE(touch_node); ASSERT_TRUE(touch_node);
web_view_impl->EnableTapHighlightAtPoint(targeted_event); web_view_impl->EnableTapHighlightAtPoint(targeted_event);
ASSERT_TRUE(web_view_impl->GetLinkHighlight(0)); const auto& highlights =
web_view_impl->GetPage()->GetLinkHighlights().link_highlights_;
ASSERT_TRUE(highlights.at(0));
GraphicsLayer* highlight_layer = GraphicsLayer* highlight_layer =
web_view_impl->GetLinkHighlight(0)->CurrentGraphicsLayerForTesting(); highlights.at(0)->CurrentGraphicsLayerForTesting();
ASSERT_TRUE(highlight_layer); ASSERT_TRUE(highlight_layer);
EXPECT_TRUE(highlight_layer->GetLinkHighlight(0)); EXPECT_TRUE(highlight_layer->GetLinkHighlight(0));
...@@ -228,7 +241,9 @@ TEST(LinkHighlightImplTest, multipleHighlights) { ...@@ -228,7 +241,9 @@ TEST(LinkHighlightImplTest, multipleHighlights) {
good_targets, highlight_nodes); good_targets, highlight_nodes);
web_view_impl->EnableTapHighlights(highlight_nodes); web_view_impl->EnableTapHighlights(highlight_nodes);
EXPECT_EQ(2U, web_view_impl->NumLinkHighlights()); const auto& highlights =
web_view_impl->GetPage()->GetLinkHighlights().link_highlights_;
EXPECT_EQ(2U, highlights.size());
Platform::Current() Platform::Current()
->GetURLLoaderMockFactory() ->GetURLLoaderMockFactory()
......
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