Commit 9f661dae authored by yosin's avatar yosin Committed by Commit bot

Introduce DragController::hasCaretIn()

This patch introduces |DragController::hasCaretIn()| as replacement of
|DragController::caretLayoutObject()| and |DragController::isContentEditable()|
to provide high-level API for improving code health.

BUG=n/a
TEST=n/a; no behavior changes

Review-Url: https://codereview.chromium.org/2272343002
Cr-Commit-Position: refs/heads/master@{#414381}
parent de780ec0
......@@ -26,6 +26,7 @@
#include "core/editing/DragCaretController.h"
#include "core/editing/EditingUtilities.h"
#include "core/frame/Settings.h"
#include "core/layout/api/LayoutViewItem.h"
#include "core/paint/PaintLayer.h"
......@@ -41,6 +42,19 @@ DragCaretController* DragCaretController::create()
return new DragCaretController;
}
bool DragCaretController::hasCaretIn(const LayoutBlock& layoutBlock) const
{
Node* node = m_position.deepEquivalent().anchorNode();
if (!node)
return false;
if (layoutBlock != CaretBase::caretLayoutObject(node))
return false;
if (rootEditableElementOf(m_position))
return true;
Settings* settings = node->ownerDocument()->frame()->settings();
return settings && settings->caretBrowsingEnabled();
}
bool DragCaretController::isContentRichlyEditable() const
{
return isRichlyEditablePosition(m_position.deepEquivalent());
......@@ -102,16 +116,6 @@ DEFINE_TRACE(DragCaretController)
visitor->trace(m_caretBase);
}
LayoutBlock* DragCaretController::caretLayoutObject() const
{
return CaretBase::caretLayoutObject(m_position.deepEquivalent().anchorNode());
}
bool DragCaretController::isContentEditable() const
{
return rootEditableElementOf(m_position);
}
void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext& context, const LayoutPoint& paintOffset) const
{
if (m_position.deepEquivalent().anchorNode()->document().frame() == frame)
......
......@@ -35,10 +35,9 @@ class DragCaretController final : public GarbageCollectedFinalized<DragCaretCont
public:
static DragCaretController* create();
LayoutBlock* caretLayoutObject() const;
void paintDragCaret(LocalFrame*, GraphicsContext&, const LayoutPoint&) const;
bool isContentEditable() const;
bool hasCaretIn(const LayoutBlock&) const;
bool isContentRichlyEditable() const;
bool hasCaret() const { return m_position.isNotNull(); }
......
......@@ -1607,7 +1607,7 @@ bool LayoutBlock::hasDragCaret() const
{
LocalFrame* frame = this->frame();
DragCaretController& dragCaretController = frame->page()->dragCaretController();
return dragCaretController.caretLayoutObject() == this && (dragCaretController.isContentEditable() || caretBrowsingEnabled(frame));
return dragCaretController.hasCaretIn(*this);
}
LayoutRect LayoutBlock::localCaretRect(InlineBox* inlineBox, int caretOffset, LayoutUnit* extraWidthToEndOfLine)
......
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