Skip to content

Commit

Permalink
FrameSet: Move UserResize() and SetIsResizing()
Browse files Browse the repository at this point in the history
... from LayoutFrameSet to HTMLFrameSetElement.

- Add |friend| to LayoutFrameSet.
- Add MouseEvent::IsLeftButton() to shorten the code.

This CL has no behavior changes.

Bug: 1347700
Change-Id: I590796badfab0596d9e9f009bda1a7805b0d9051
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3787823
Reviewed-by: Koji Ishii <kojii@chromium.org>
Commit-Queue: Koji Ishii <kojii@chromium.org>
Auto-Submit: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1028632}
  • Loading branch information
tkent-google authored and Chromium LUCI CQ committed Jul 27, 2022
1 parent 1ae5601 commit 3027ae9
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 55 deletions.
4 changes: 4 additions & 0 deletions third_party/blink/renderer/core/events/mouse_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ int16_t MouseEvent::button() const {
return button_;
}

bool MouseEvent::IsLeftButton() const {
return button() == static_cast<int16_t>(WebPointerProperties::Button::kLeft);
}

unsigned MouseEvent::which() const {
// For the DOM, the return values for left, middle and right mouse buttons are
// 0, 1, 2, respectively.
Expand Down
2 changes: 2 additions & 0 deletions third_party/blink/renderer/core/events/mouse_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class CORE_EXPORT MouseEvent : public UIEventWithKeyState {
// WinIE uses 1,4,2 for left/middle/right but not for click (just for
// mousedown/up, maybe others), but we will match the standard DOM.
virtual int16_t button() const;
// Returns true if |button()| is WebPointerProperties::Button::kLeft.
bool IsLeftButton() const;
uint16_t buttons() const { return buttons_; }
bool ButtonDown() const { return button_ != -1; }
EventTarget* relatedTarget() const { return related_target_.Get(); }
Expand Down
45 changes: 44 additions & 1 deletion third_party/blink/renderer/core/html/html_frame_set_element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "third_party/blink/renderer/core/html/html_collection.h"
#include "third_party/blink/renderer/core/html/html_frame_element.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/input/event_handler.h"
#include "third_party/blink/renderer/core/layout/layout_frame_set.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"

Expand Down Expand Up @@ -256,13 +257,14 @@ void HTMLFrameSetElement::AttachLayoutTree(AttachContext& context) {
}

HTMLElement::AttachLayoutTree(context);
is_resizing_ = false;
}

void HTMLFrameSetElement::DefaultEventHandler(Event& evt) {
auto* mouse_event = DynamicTo<MouseEvent>(evt);
if (mouse_event && !noresize_ && GetLayoutObject() &&
GetLayoutObject()->IsFrameSet()) {
if (To<LayoutFrameSet>(GetLayoutObject())->UserResize(*mouse_event)) {
if (UserResize(*mouse_event)) {
evt.SetDefaultHandled();
return;
}
Expand Down Expand Up @@ -292,4 +294,45 @@ void HTMLFrameSetElement::WillRecalcStyle(const StyleRecalcChange) {
}
}

bool HTMLFrameSetElement::UserResize(const MouseEvent& event) {
auto& layout_frame_set = *To<LayoutFrameSet>(GetLayoutObject());
if (!is_resizing_) {
if (layout_frame_set.NeedsLayout())
return false;
if (event.type() == event_type_names::kMousedown && event.IsLeftButton()) {
gfx::PointF local_pos =
layout_frame_set.AbsoluteToLocalPoint(event.AbsoluteLocation());
layout_frame_set.StartResizing(layout_frame_set.cols_, local_pos.x());
layout_frame_set.StartResizing(layout_frame_set.rows_, local_pos.y());
if (layout_frame_set.cols_.split_being_resized_ !=
LayoutFrameSet::kNoSplit ||
layout_frame_set.rows_.split_being_resized_ !=
LayoutFrameSet::kNoSplit) {
SetIsResizing(true);
return true;
}
}
} else {
if (event.type() == event_type_names::kMousemove ||
(event.type() == event_type_names::kMouseup && event.IsLeftButton())) {
gfx::PointF local_pos =
layout_frame_set.AbsoluteToLocalPoint(event.AbsoluteLocation());
layout_frame_set.ContinueResizing(layout_frame_set.cols_, local_pos.x());
layout_frame_set.ContinueResizing(layout_frame_set.rows_, local_pos.y());
if (event.type() == event_type_names::kMouseup && event.IsLeftButton()) {
SetIsResizing(false);
return true;
}
}
}

return false;
}

void HTMLFrameSetElement::SetIsResizing(bool is_resizing) {
is_resizing_ = is_resizing;
if (LocalFrame* frame = GetDocument().GetFrame())
frame->GetEventHandler().SetResizingFrameSet(is_resizing ? this : nullptr);
}

} // namespace blink
7 changes: 7 additions & 0 deletions third_party/blink/renderer/core/html/html_frame_set_element.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

namespace blink {

class MouseEvent;

class HTMLFrameSetElement final : public HTMLElement {
DEFINE_WRAPPERTYPEINFO();

Expand Down Expand Up @@ -83,6 +85,9 @@ class HTMLFrameSetElement final : public HTMLElement {
InsertionNotificationRequest InsertedInto(ContainerNode&) override;
void WillRecalcStyle(const StyleRecalcChange) override;

bool UserResize(const MouseEvent& event);
void SetIsResizing(bool is_resizing);

Vector<HTMLDimension> row_lengths_;
Vector<HTMLDimension> col_lengths_;

Expand All @@ -94,6 +99,8 @@ class HTMLFrameSetElement final : public HTMLElement {
bool frameborder_;
bool frameborder_set_;
bool noresize_;

bool is_resizing_ = false;
};

} // namespace blink
Expand Down
49 changes: 1 addition & 48 deletions third_party/blink/renderer/core/layout/layout_frame_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/html/html_dimension.h"
#include "third_party/blink/renderer/core/html/html_frame_set_element.h"
#include "third_party/blink/renderer/core/input/event_handler.h"
#include "third_party/blink/renderer/core/layout/layout_frame.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/paint/frame_set_painter.h"
Expand All @@ -50,7 +49,7 @@ static int AdjustSizeToRemainingSize(int current,
}

LayoutFrameSet::LayoutFrameSet(HTMLFrameSetElement* frame_set)
: LayoutBox(frame_set), is_resizing_(false) {
: LayoutBox(frame_set) {
SetInline(false);
}

Expand Down Expand Up @@ -489,52 +488,6 @@ void LayoutFrameSet::ContinueResizing(GridAxis& axis, int position) {
layout_invalidation_reason::kSizeChanged);
}

bool LayoutFrameSet::UserResize(const MouseEvent& evt) {
NOT_DESTROYED();
if (!is_resizing_) {
if (NeedsLayout())
return false;
if (evt.type() == event_type_names::kMousedown &&
evt.button() ==
static_cast<int16_t>(WebPointerProperties::Button::kLeft)) {
gfx::PointF local_pos = AbsoluteToLocalPoint(evt.AbsoluteLocation());
StartResizing(cols_, local_pos.x());
StartResizing(rows_, local_pos.y());
if (cols_.split_being_resized_ != kNoSplit ||
rows_.split_being_resized_ != kNoSplit) {
SetIsResizing(true);
return true;
}
}
} else {
if (evt.type() == event_type_names::kMousemove ||
(evt.type() == event_type_names::kMouseup &&
evt.button() ==
static_cast<int16_t>(WebPointerProperties::Button::kLeft))) {
gfx::PointF local_pos = AbsoluteToLocalPoint(evt.AbsoluteLocation());
ContinueResizing(cols_, local_pos.x());
ContinueResizing(rows_, local_pos.y());
if (evt.type() == event_type_names::kMouseup &&
evt.button() ==
static_cast<int16_t>(WebPointerProperties::Button::kLeft)) {
SetIsResizing(false);
return true;
}
}
}

return false;
}

void LayoutFrameSet::SetIsResizing(bool is_resizing) {
NOT_DESTROYED();
is_resizing_ = is_resizing;
if (LocalFrame* frame = GetFrame()) {
frame->GetEventHandler().SetResizingFrameSet(is_resizing ? FrameSet()
: nullptr);
}
}

bool LayoutFrameSet::CanResizeRow(const gfx::Point& p) const {
NOT_DESTROYED();
int r = HitTestSplit(rows_, p.y());
Expand Down
8 changes: 2 additions & 6 deletions third_party/blink/renderer/core/layout/layout_frame_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ namespace blink {

class HTMLDimension;
class HTMLFrameSetElement;
class MouseEvent;

enum FrameEdge {
kLeftFrameEdge,
Expand Down Expand Up @@ -96,8 +95,6 @@ class LayoutFrameSet final : public LayoutBox {

FrameEdgeInfo EdgeInfo() const;

bool UserResize(const MouseEvent&);

bool CanResizeRow(const gfx::Point&) const;
bool CanResizeColumn(const gfx::Point&) const;

Expand Down Expand Up @@ -170,8 +167,6 @@ class LayoutFrameSet final : public LayoutBox {
bool IsChildAllowed(LayoutObject*, const ComputedStyle&) const override;
CursorDirective GetCursor(const PhysicalOffset&, ui::Cursor&) const override;

void SetIsResizing(bool);

void LayOutAxis(GridAxis&, const Vector<HTMLDimension>&, int available_space);
void ComputeEdgeInfo();
void FillFromEdgeInfo(const FrameEdgeInfo&, int r, int c);
Expand All @@ -188,7 +183,8 @@ class LayoutFrameSet final : public LayoutBox {
GridAxis rows_;
GridAxis cols_;

bool is_resizing_;
// Temporal friend until we complete to move the resizing code.
friend HTMLFrameSetElement;
};

template <>
Expand Down

0 comments on commit 3027ae9

Please sign in to comment.