Commit 1a19c914 authored by Daniel Cheng's avatar Daniel Cheng Committed by Commit Bot

[OOPIF] Refactor client and local root into WebFrameWidgetBase.

Extract some more common code into WebFrameWidgetBase. The end goal is
to completely merge WebFrameWidgetImpl and WebViewFrameWidget into
WebFrameWidgetBase. This is an intermediate step to make it easier to
create the frame widget before creating the local frame root: by sharing
storage in the base class, the followup patch to invert creation order
will only have to update pointers in one place.

Bug: 820787
Change-Id: I5f096c8a8d74abb6b6773ff36c75288b998d3880
Reviewed-on: https://chromium-review.googlesource.com/1014017Reviewed-by: default avatarAlbert J. Wong <ajwong@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551264}
parent f9b56bc5
......@@ -34,16 +34,6 @@
namespace blink {
namespace {
// Helper to get LocalFrame* from WebLocalFrame*.
// TODO(dcheng): This should be moved into WebLocalFrame.
LocalFrame* ToCoreFrame(WebLocalFrame* frame) {
return ToWebLocalFrameImpl(frame)->GetFrame();
}
} // namespace
// Ensure that the WebDragOperation enum values stay in sync with the original
// DragOperation constants.
STATIC_ASSERT_ENUM(kDragOperationNone, kWebDragOperationNone);
......@@ -57,12 +47,30 @@ STATIC_ASSERT_ENUM(kDragOperationEvery, kWebDragOperationEvery);
bool WebFrameWidgetBase::ignore_input_events_ = false;
WebFrameWidgetBase::WebFrameWidgetBase()
: fling_modifier_(0),
WebFrameWidgetBase::WebFrameWidgetBase(WebWidgetClient& client)
: client_(&client),
fling_modifier_(0),
fling_source_device_(kWebGestureDeviceUninitialized) {}
WebFrameWidgetBase::~WebFrameWidgetBase() = default;
void WebFrameWidgetBase::BindLocalRoot(WebLocalFrame& local_root) {
local_root_ = ToWebLocalFrameImpl(local_root);
local_root_->SetFrameWidget(this);
Initialize();
}
void WebFrameWidgetBase::Close() {
local_root_->SetFrameWidget(nullptr);
local_root_ = nullptr;
client_ = nullptr;
}
WebLocalFrame* WebFrameWidgetBase::LocalRoot() const {
return local_root_;
}
WebDragOperation WebFrameWidgetBase::DragTargetDragEnter(
const WebDragData& web_drag_data,
const WebFloatPoint& point_in_viewport,
......@@ -110,7 +118,7 @@ void WebFrameWidgetBase::DragTargetDragLeave(
static_cast<DragOperation>(operations_allowed_));
GetPage()->GetDragController().DragExited(&drag_data,
*ToCoreFrame(LocalRoot()));
*local_root_->GetFrame());
// FIXME: why is the drag scroll timer not stopped here?
......@@ -147,7 +155,7 @@ void WebFrameWidgetBase::DragTargetDrop(const WebDragData& web_drag_data,
static_cast<DragOperation>(operations_allowed_));
GetPage()->GetDragController().PerformDrag(&drag_data,
*ToCoreFrame(LocalRoot()));
*local_root_->GetFrame());
}
drag_operation_ = kWebDragOperationNone;
current_drag_data_ = nullptr;
......@@ -157,7 +165,7 @@ void WebFrameWidgetBase::DragSourceEndedAt(
const WebFloatPoint& point_in_viewport,
const WebFloatPoint& screen_point,
WebDragOperation operation) {
if (!LocalRoot()) {
if (!local_root_) {
// We should figure out why |local_root_| could be nullptr
// (https://crbug.com/792345).
return;
......@@ -175,10 +183,8 @@ void WebFrameWidgetBase::DragSourceEndedAt(
WebPointerProperties::Button::kLeft, 0, WebInputEvent::kNoModifiers,
CurrentTimeTicksInSeconds());
fake_mouse_move.SetFrameScale(1);
ToCoreFrame(LocalRoot())
->GetEventHandler()
.DragSourceEndedAt(fake_mouse_move,
static_cast<DragOperation>(operation));
local_root_->GetFrame()->GetEventHandler().DragSourceEndedAt(
fake_mouse_move, static_cast<DragOperation>(operation));
}
void WebFrameWidgetBase::DragSourceSystemDragEnded() {
......@@ -228,7 +234,7 @@ WebDragOperation WebFrameWidgetBase::DragTargetDragEnterOrOver(
DragSession drag_session;
drag_session = GetPage()->GetDragController().DragEnteredOrUpdated(
&drag_data, *ToCoreFrame(LocalRoot()));
&drag_data, *local_root_->GetFrame());
DragOperation drop_effect = drag_session.operation;
......@@ -248,7 +254,7 @@ WebFloatPoint WebFrameWidgetBase::ViewportToRootFrame(
}
WebViewImpl* WebFrameWidgetBase::View() const {
return ToWebLocalFrameImpl(LocalRoot())->ViewImpl();
return local_root_->ViewImpl();
}
Page* WebFrameWidgetBase::GetPage() const {
......@@ -286,6 +292,7 @@ void WebFrameWidgetBase::RequestDecode(
}
void WebFrameWidgetBase::Trace(blink::Visitor* visitor) {
visitor->Trace(local_root_);
visitor->Trace(current_drag_data_);
}
......@@ -296,8 +303,8 @@ void WebFrameWidgetBase::PointerLockMouseEvent(
const WebInputEvent& input_event = coalesced_event.Event();
const WebMouseEvent& mouse_event =
static_cast<const WebMouseEvent&>(input_event);
WebMouseEvent transformed_event = TransformWebMouseEvent(
ToWebLocalFrameImpl(LocalRoot())->GetFrameView(), mouse_event);
WebMouseEvent transformed_event =
TransformWebMouseEvent(local_root_->GetFrameView(), mouse_event);
LocalFrame* focusedFrame = FocusedLocalFrameInWidget();
if (focusedFrame) {
......@@ -355,16 +362,16 @@ void WebFrameWidgetBase::ShowContextMenu(WebMenuSourceType source_type) {
}
LocalFrame* WebFrameWidgetBase::FocusedLocalFrameInWidget() const {
if (!LocalRoot()) {
if (!local_root_) {
// WebFrameWidget is created in the call to CreateFrame. The corresponding
// RenderWidget, however, might not swap in right away (InstallNewDocument()
// will lead to it swapping in). During this interval LocalRoot() is nullptr
// will lead to it swapping in). During this interval local_root_ is nullptr
// (see https://crbug.com/792345).
return nullptr;
}
LocalFrame* frame = GetPage()->GetFocusController().FocusedFrame();
return (frame && frame->LocalFrameRoot() == ToCoreFrame(LocalRoot()))
return (frame && frame->LocalFrameRoot() == local_root_->GetFrame())
? frame
: nullptr;
}
......@@ -403,8 +410,8 @@ bool WebFrameWidgetBase::ScrollBy(const WebFloatSize& delta,
synthetic_wheel.SetPositionInScreen(global_position_on_fling_start_.x,
global_position_on_fling_start_.y);
// TODO(wjmaclean): Is LocalRoot() the right frame to use here?
if (GetPageWidgetEventHandler()->HandleMouseWheel(*ToCoreFrame(LocalRoot()),
// TODO(wjmaclean): Is local_root_ the right frame to use here?
if (GetPageWidgetEventHandler()->HandleMouseWheel(*local_root_->GetFrame(),
synthetic_wheel) !=
WebInputEventResult::kNotHandled) {
return true;
......@@ -481,14 +488,13 @@ WebInputEventResult WebFrameWidgetBase::HandleGestureFlingEvent(
ScheduleAnimation();
WebGestureEvent scaled_event =
TransformWebGestureEvent(ToCoreFrame(LocalRoot())->View(), event);
TransformWebGestureEvent(local_root_->GetFrameView(), event);
// Plugins may need to see GestureFlingStart to balance
// GestureScrollBegin (since the former replaces GestureScrollEnd when
// transitioning to a fling).
// TODO(dtapuska): Why isn't the response used?
ToCoreFrame(LocalRoot())
->GetEventHandler()
.HandleGestureScrollEvent(scaled_event);
local_root_->GetFrame()->GetEventHandler().HandleGestureScrollEvent(
scaled_event);
event_result = WebInputEventResult::kHandledSystem;
break;
......@@ -537,9 +543,8 @@ void WebFrameWidgetBase::UpdateGestureAnimation(
if (last_fling_source_device != kWebGestureDeviceSyntheticAutoscroll) {
WebGestureEvent end_scroll_event = CreateGestureScrollEventFromFling(
WebInputEvent::kGestureScrollEnd, last_fling_source_device);
ToCoreFrame(LocalRoot())
->GetEventHandler()
.HandleGestureScrollEnd(end_scroll_event);
local_root_->GetFrame()->GetEventHandler().HandleGestureScrollEnd(
end_scroll_event);
}
}
}
......
......@@ -27,7 +27,7 @@ class WebActiveGestureAnimation;
class WebImage;
class WebLayer;
class WebLayerTreeView;
class WebLocalFrame;
class WebLocalFrameImpl;
class WebViewImpl;
class HitTestResult;
struct WebFloatPoint;
......@@ -37,17 +37,22 @@ class CORE_EXPORT WebFrameWidgetBase
public WebFrameWidget,
public WebGestureCurveTarget {
public:
WebFrameWidgetBase();
explicit WebFrameWidgetBase(WebWidgetClient&);
virtual ~WebFrameWidgetBase();
WebWidgetClient* Client() const { return client_; }
WebLocalFrameImpl* LocalRootImpl() const { return local_root_; }
void BindLocalRoot(WebLocalFrame&);
// Called once the local root is bound via |BindLocalRoot()|.
virtual void Initialize() = 0;
virtual bool ForSubframe() const = 0;
virtual void ScheduleAnimation() = 0;
virtual void IntrinsicSizingInfoChanged(const IntrinsicSizingInfo&) {}
virtual base::WeakPtr<CompositorMutatorImpl> EnsureCompositorMutator(
scoped_refptr<base::SingleThreadTaskRunner>* mutator_task_runner) = 0;
virtual WebWidgetClient* Client() const = 0;
// Sets the root graphics layer. |GraphicsLayer| can be null when detaching
// the root layer.
virtual void SetRootGraphicsLayer(GraphicsLayer*) = 0;
......@@ -71,6 +76,8 @@ class CORE_EXPORT WebFrameWidgetBase
const WebFloatSize& velocity) override;
// WebFrameWidget implementation.
void Close() override;
WebLocalFrame* LocalRoot() const override;
WebDragOperation DragTargetDragEnter(const WebDragData&,
const WebFloatPoint& point_in_viewport,
const WebFloatPoint& screen_point,
......@@ -171,6 +178,13 @@ class CORE_EXPORT WebFrameWidgetBase
WebGestureDevice) const;
void CancelDrag();
WebWidgetClient* client_;
// WebFrameWidget is associated with a subtree of the frame tree,
// corresponding to a maximal connected tree of LocalFrames. This member
// points to the root of that subtree.
Member<WebLocalFrameImpl> local_root_;
std::unique_ptr<WebActiveGestureAnimation> gesture_animation_;
WebFloatPoint position_on_fling_start_;
WebFloatPoint global_position_on_fling_start_;
......
......@@ -69,7 +69,7 @@ using WebFrameWidgetsSet =
class WebFrameWidgetImpl final : public WebFrameWidgetBase,
public PageWidgetEventHandler {
public:
static WebFrameWidgetImpl* Create(WebWidgetClient*, WebLocalFrame*);
static WebFrameWidgetImpl* Create(WebWidgetClient&);
~WebFrameWidgetImpl();
......@@ -111,7 +111,6 @@ class WebFrameWidgetImpl final : public WebFrameWidgetBase,
bool subtree_throttled) override;
// WebFrameWidget implementation.
WebLocalFrameImpl* LocalRoot() const override { return local_root_; }
void SetVisibilityState(mojom::PageVisibilityState) override;
void SetBackgroundColorOverride(WebColor) override;
void ClearBackgroundColorOverride() override;
......@@ -135,12 +134,12 @@ class WebFrameWidgetImpl final : public WebFrameWidgetBase,
override;
// WebFrameWidgetBase overrides:
void Initialize() override;
bool ForSubframe() const override { return true; }
void ScheduleAnimation() override;
void IntrinsicSizingInfoChanged(const IntrinsicSizingInfo&) override;
void DidCreateLocalRootView() override;
WebWidgetClient* Client() const override { return client_; }
void SetRootGraphicsLayer(GraphicsLayer*) override;
void SetRootLayer(WebLayer*) override;
WebLayerTreeView* GetLayerTreeView() const override;
......@@ -166,7 +165,7 @@ class WebFrameWidgetImpl final : public WebFrameWidgetBase,
private:
friend class WebFrameWidget; // For WebFrameWidget::create.
explicit WebFrameWidgetImpl(WebWidgetClient*, WebLocalFrame*);
explicit WebFrameWidgetImpl(WebWidgetClient&);
// Perform a hit test for a point relative to the root frame of the page.
HitTestResult HitTestResultForRootFramePos(
......@@ -202,13 +201,6 @@ class WebFrameWidgetImpl final : public WebFrameWidgetBase,
LayoutRect& rect_to_scroll,
WebScrollIntoViewParams& params);
WebWidgetClient* client_;
// WebFrameWidget is associated with a subtree of the frame tree,
// corresponding to a maximal connected tree of LocalFrames. This member
// points to the root of that subtree.
Member<WebLocalFrameImpl> local_root_;
WTF::Optional<WebSize> size_;
// If set, the (plugin) node which has mouse capture.
......
......@@ -12,15 +12,10 @@
namespace blink {
WebViewFrameWidget::WebViewFrameWidget(WebWidgetClient& client,
WebViewImpl& web_view,
WebLocalFrameImpl& main_frame)
: client_(&client),
WebViewImpl& web_view)
: WebFrameWidgetBase(client),
web_view_(&web_view),
main_frame_(&main_frame),
self_keep_alive_(this) {
main_frame_->SetFrameWidget(this);
web_view_->SetCompositorVisibility(true);
}
self_keep_alive_(this) {}
WebViewFrameWidget::~WebViewFrameWidget() = default;
......@@ -30,10 +25,9 @@ void WebViewFrameWidget::Close() {
// updated. If the main frame is being swapped, then
// m_webView()->mainFrameImpl() will no longer point to the original frame.
web_view_->SetCompositorVisibility(false);
main_frame_->SetFrameWidget(nullptr);
main_frame_ = nullptr;
web_view_ = nullptr;
client_ = nullptr;
WebFrameWidgetBase::Close();
// Note: this intentionally does not forward to WebView::close(), to make it
// easier to untangle the cleanup logic later.
......@@ -186,10 +180,6 @@ void WebViewFrameWidget::SetBaseBackgroundColor(WebColor color) {
web_view_->SetBaseBackgroundColor(color);
}
WebLocalFrameImpl* WebViewFrameWidget::LocalRoot() const {
return web_view_->MainFrameImpl();
}
WebInputMethodController*
WebViewFrameWidget::GetActiveWebInputMethodController() const {
return web_view_->GetActiveWebInputMethodController();
......@@ -199,6 +189,10 @@ bool WebViewFrameWidget::ScrollFocusedEditableElementIntoView() {
return web_view_->ScrollFocusedEditableElementIntoView();
}
void WebViewFrameWidget::Initialize() {
web_view_->SetCompositorVisibility(true);
}
void WebViewFrameWidget::ScheduleAnimation() {
web_view_->ScheduleAnimationForWidget();
}
......@@ -238,7 +232,6 @@ HitTestResult WebViewFrameWidget::CoreHitTestResultAt(const WebPoint& point) {
}
void WebViewFrameWidget::Trace(blink::Visitor* visitor) {
visitor->Trace(main_frame_);
WebFrameWidgetBase::Trace(visitor);
}
......
......@@ -35,9 +35,7 @@ class WebWidgetClient;
// https://goo.gl/7yVrnb.
class CORE_EXPORT WebViewFrameWidget : public WebFrameWidgetBase {
public:
explicit WebViewFrameWidget(WebWidgetClient&,
WebViewImpl&,
WebLocalFrameImpl&);
explicit WebViewFrameWidget(WebWidgetClient&, WebViewImpl&);
virtual ~WebViewFrameWidget();
// WebFrameWidget overrides:
......@@ -84,11 +82,11 @@ class CORE_EXPORT WebViewFrameWidget : public WebFrameWidgetBase {
void SetBaseBackgroundColorOverride(WebColor) override;
void ClearBaseBackgroundColorOverride() override;
void SetBaseBackgroundColor(WebColor) override;
WebLocalFrameImpl* LocalRoot() const override;
WebInputMethodController* GetActiveWebInputMethodController() const override;
bool ScrollFocusedEditableElementIntoView() override;
// WebFrameWidgetBase overrides:
void Initialize() override;
bool ForSubframe() const override { return false; }
void ScheduleAnimation() override;
base::WeakPtr<CompositorMutatorImpl> EnsureCompositorMutator(
......@@ -98,7 +96,6 @@ class CORE_EXPORT WebViewFrameWidget : public WebFrameWidgetBase {
void SetRootLayer(WebLayer*) override;
WebLayerTreeView* GetLayerTreeView() const override;
CompositorAnimationHost* AnimationHost() const override;
WebWidgetClient* Client() const override { return client_; }
WebHitTestResult HitTestResultAt(const WebPoint&) override;
HitTestResult CoreHitTestResultAt(const WebPoint&) override;
......@@ -107,9 +104,7 @@ class CORE_EXPORT WebViewFrameWidget : public WebFrameWidgetBase {
private:
PageWidgetEventHandler* GetPageWidgetEventHandler() override;
WebWidgetClient* client_;
scoped_refptr<WebViewImpl> web_view_;
Member<WebLocalFrameImpl> main_frame_;
SelfKeepAlive<WebViewFrameWidget> self_keep_alive_;
......
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