Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Unified Diff: Source/core/editing/Caret.cpp

Issue 275563003: Change caret to show language direction (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: WIP patch for directional caret Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/editing/Caret.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/Caret.cpp
diff --git a/Source/core/editing/Caret.cpp b/Source/core/editing/Caret.cpp
index 2b3c1d6ccf2ebb25d5d785e3293dcadc09b02066..fb7e9c47681ae4186ffce7369740fa3274d5db3e 100644
--- a/Source/core/editing/Caret.cpp
+++ b/Source/core/editing/Caret.cpp
@@ -179,6 +179,18 @@ IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const LayoutRect& rect
return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoundingBox();
}
+void CaretBase::updateDirectionPointer(const RenderObject* renderObject, LayoutRect& rect)
+{
+ if (!renderObject)
+ return;
+
+ // Extra rect are drawn, need to refresh more area.
+ TextDirection containerDirection = renderObject->style()->direction();
+ rect.setWidth(rect.width() + LayoutUnit(2));
+ if (containerDirection == RTL)
+ rect.setX(rect.x() - LayoutUnit(2));
+}
+
void CaretBase::repaintCaretForLocalRect(Node* node, const LayoutRect& rect)
{
RenderObject* caretPainter = caretRenderer(node);
@@ -190,6 +202,7 @@ void CaretBase::repaintCaretForLocalRect(Node* node, const LayoutRect& rect)
LayoutRect inflatedRect = rect;
inflatedRect.inflate(1);
+ updateDirectionPointer(caretPainter, inflatedRect);
caretPainter->repaintRectangle(inflatedRect);
}
@@ -223,8 +236,11 @@ void CaretBase::invalidateCaretRect(Node* node, bool caretRectChanged)
return;
if (RenderView* view = node->document().renderView()) {
- if (shouldRepaintCaret(view, node->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable)))
- repaintCaretForLocalRect(node, localCaretRectWithoutUpdate());
+ if (shouldRepaintCaret(view, node->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable))) {
+ LayoutRect drawingRect = localCaretRectWithoutUpdate();
+ updateDirectionPointer(caretRenderer(node), drawingRect);
+ repaintCaretForLocalRect(node, drawingRect);
+ }
}
}
@@ -242,6 +258,18 @@ void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi
if (caret.isEmpty())
return;
+ TextDirection containerDirection = toRenderBoxModelObject(renderer)->style()->direction();
+ LayoutRect directionPointerCaret = caret;
+
+ // Drawing different Caret which shows editing style similar to IE.
+ if (containerDirection == LTR)
+ directionPointerCaret.setX(directionPointerCaret.x() + 1);
+ else
+ directionPointerCaret.setX(directionPointerCaret.x() - 2);
+
+ directionPointerCaret.setWidth(LayoutUnit(2));
+ directionPointerCaret.setHeight(LayoutUnit(1));
+
Color caretColor = Color::black;
Element* element;
@@ -254,6 +282,14 @@ void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi
caretColor = element->renderer()->resolveColor(CSSPropertyColor);
context->fillRect(caret, caretColor);
+ context->fillRect(directionPointerCaret, caretColor);
+
+ // Update directionPointerCaret points and lets draw one more small rect to match IE.
+ directionPointerCaret.setY(caret.y() + LayoutUnit(1));
+ directionPointerCaret.setWidth(LayoutUnit(1));
+ if (containerDirection == RTL)
+ directionPointerCaret.setX(directionPointerCaret.x() + 1);
+ context->fillRect(directionPointerCaret, caretColor);
}
void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p, const LayoutPoint& paintOffset, const LayoutRect& clipRect) const
« no previous file with comments | « Source/core/editing/Caret.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698