Commit 261e7687 authored by Dave Tapuska's avatar Dave Tapuska Committed by Commit Bot

Collapse CalculateSelectionBounds into WebFrameWidgetBase.

Make the implementation common for both frame widgets. For OOPIFs the
visual viewport transformation will be 1:1 so this code is the same.
No behavioral changes intended.

BUG=1097816

Change-Id: I5be86c5b9f5be377b8e0d8f7efda4258ffebdb7b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2538010Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827793}
parent 5ccd3bff
......@@ -29,6 +29,7 @@
#include "third_party/blink/renderer/core/content_capture/content_capture_manager.h"
#include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/layout_tree_builder_traversal.h"
#include "third_party/blink/renderer/core/editing/frame_selection.h"
#include "third_party/blink/renderer/core/events/current_input_event.h"
#include "third_party/blink/renderer/core/events/web_input_event_conversion.h"
#include "third_party/blink/renderer/core/events/wheel_event.h"
......@@ -2841,6 +2842,27 @@ void WebFrameWidgetBase::ForEachRemoteFrameControlledByWidget(
callback);
}
void WebFrameWidgetBase::CalculateSelectionBounds(gfx::Rect& anchor_root_frame,
gfx::Rect& focus_root_frame) {
auto* local_frame = DynamicTo<LocalFrame>(FocusedCoreFrame());
if (!local_frame)
return;
IntRect anchor;
IntRect focus;
if (!local_frame->Selection().ComputeAbsoluteBounds(anchor, focus))
return;
// Apply the visual viewport for main frames this will apply the page scale.
// For subframes it will just be a 1:1 transformation and the browser
// will then apply later transformations to these rects.
VisualViewport& visual_viewport = GetPage()->GetVisualViewport();
anchor_root_frame = visual_viewport.RootFrameToViewport(
local_frame->View()->ConvertToRootFrame(anchor));
focus_root_frame = visual_viewport.RootFrameToViewport(
local_frame->View()->ConvertToRootFrame(focus));
}
void WebFrameWidgetBase::BatterySavingsChanged(WebBatterySavingsFlags savings) {
widget_base_->LayerTreeHost()->SetEnableFrameRateThrottling(
savings & kAllowReducedFrameRate);
......
......@@ -606,8 +606,8 @@ class CORE_EXPORT WebFrameWidgetBase
// Calculates the selection bounds in the root frame. Returns bounds unchanged
// when there is no focused frame or no selection.
virtual void CalculateSelectionBounds(gfx::Rect& anchor_in_root_frame,
gfx::Rect& focus_in_root_frame) = 0;
void CalculateSelectionBounds(gfx::Rect& anchor_in_root_frame,
gfx::Rect& focus_in_root_frame);
// Returns if auto resize mode is enabled.
bool AutoResizeMode();
......
......@@ -48,7 +48,6 @@
#include "third_party/blink/renderer/core/editing/editing_utilities.h"
#include "third_party/blink/renderer/core/editing/editor.h"
#include "third_party/blink/renderer/core/editing/ephemeral_range.h"
#include "third_party/blink/renderer/core/editing/frame_selection.h"
#include "third_party/blink/renderer/core/editing/ime/input_method_controller.h"
#include "third_party/blink/renderer/core/editing/plain_text_range.h"
#include "third_party/blink/renderer/core/editing/selection_template.h"
......@@ -405,23 +404,6 @@ void WebFrameWidgetImpl::FocusChanged(bool enable) {
}
}
void WebFrameWidgetImpl::CalculateSelectionBounds(gfx::Rect& anchor_root_frame,
gfx::Rect& focus_root_frame) {
const LocalFrame* local_frame = FocusedLocalFrameInWidget();
if (!local_frame)
return;
IntRect anchor;
IntRect focus;
if (!local_frame->Selection().ComputeAbsoluteBounds(anchor, focus))
return;
// FIXME: This doesn't apply page scale. This should probably be contents to
// viewport. crbug.com/459293.
anchor_root_frame = local_frame->View()->ConvertToRootFrame(anchor);
focus_root_frame = local_frame->View()->ConvertToRootFrame(focus);
}
void WebFrameWidgetImpl::SetIsInertForSubFrame(bool inert) {
DCHECK(LocalRootImpl()->Parent());
DCHECK(LocalRootImpl()->Parent()->IsWebRemoteFrame());
......
......@@ -118,7 +118,6 @@ class WebFrameWidgetImpl final : public WebFrameWidgetBase {
float device_scale_factor) override;
void ApplyVisualPropertiesSizing(
const VisualProperties& visual_properties) override;
void CalculateSelectionBounds(gfx::Rect& anchor, gfx::Rect& focus) override;
// FrameWidget overrides:
void SetRootLayer(scoped_refptr<cc::Layer>) override;
......
......@@ -129,29 +129,6 @@ void WebViewFrameWidget::SetWindowRect(const gfx::Rect& window_rect) {
View()->SetWindowRect(window_rect);
}
void WebViewFrameWidget::CalculateSelectionBounds(gfx::Rect& anchor_root_frame,
gfx::Rect& focus_root_frame) {
const Frame* frame = View()->FocusedCoreFrame();
const auto* local_frame = DynamicTo<LocalFrame>(frame);
if (!local_frame)
return;
LocalFrameView* frame_view = local_frame->View();
if (!frame_view)
return;
IntRect anchor;
IntRect focus;
if (!local_frame->Selection().ComputeAbsoluteBounds(anchor, focus))
return;
VisualViewport& visual_viewport = GetPage()->GetVisualViewport();
anchor_root_frame = visual_viewport.RootFrameToViewport(
frame_view->ConvertToRootFrame(anchor));
focus_root_frame = visual_viewport.RootFrameToViewport(
frame_view->ConvertToRootFrame(focus));
}
bool WebViewFrameWidget::ScrollFocusedEditableElementIntoView() {
return web_view_->ScrollFocusedEditableElementIntoView();
}
......
......@@ -85,7 +85,6 @@ class CORE_EXPORT WebViewFrameWidget : public WebFrameWidgetBase {
float maximum) override;
void ApplyVisualPropertiesSizing(
const VisualProperties& visual_properties) override;
void CalculateSelectionBounds(gfx::Rect& anchor, gfx::Rect& focus) override;
// FrameWidget overrides:
void SetRootLayer(scoped_refptr<cc::Layer>) 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