OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 RenderObject* caretPainter = caretRenderer(node); | 172 RenderObject* caretPainter = caretRenderer(node); |
173 if (!caretPainter) | 173 if (!caretPainter) |
174 return IntRect(); | 174 return IntRect(); |
175 | 175 |
176 LayoutRect localRect(rect); | 176 LayoutRect localRect(rect); |
177 if (caretPainter->isBox()) | 177 if (caretPainter->isBox()) |
178 toRenderBox(caretPainter)->flipForWritingMode(localRect); | 178 toRenderBox(caretPainter)->flipForWritingMode(localRect); |
179 return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoun
dingBox(); | 179 return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoun
dingBox(); |
180 } | 180 } |
181 | 181 |
| 182 void CaretBase::updateDirectionPointer(const RenderObject* renderObject, LayoutR
ect& rect) |
| 183 { |
| 184 if (!renderObject) |
| 185 return; |
| 186 |
| 187 // Extra rect are drawn, need to refresh more area. |
| 188 TextDirection containerDirection = renderObject->style()->direction(); |
| 189 rect.setWidth(rect.width() + LayoutUnit(2)); |
| 190 if (containerDirection == RTL) |
| 191 rect.setX(rect.x() - LayoutUnit(2)); |
| 192 } |
| 193 |
182 void CaretBase::repaintCaretForLocalRect(Node* node, const LayoutRect& rect) | 194 void CaretBase::repaintCaretForLocalRect(Node* node, const LayoutRect& rect) |
183 { | 195 { |
184 RenderObject* caretPainter = caretRenderer(node); | 196 RenderObject* caretPainter = caretRenderer(node); |
185 if (!caretPainter) | 197 if (!caretPainter) |
186 return; | 198 return; |
187 | 199 |
188 // FIXME: Need to over-paint 1 pixel to workaround some rounding problems. | 200 // FIXME: Need to over-paint 1 pixel to workaround some rounding problems. |
189 // https://bugs.webkit.org/show_bug.cgi?id=108283 | 201 // https://bugs.webkit.org/show_bug.cgi?id=108283 |
190 LayoutRect inflatedRect = rect; | 202 LayoutRect inflatedRect = rect; |
191 inflatedRect.inflate(1); | 203 inflatedRect.inflate(1); |
192 | 204 |
| 205 updateDirectionPointer(caretPainter, inflatedRect); |
193 caretPainter->repaintRectangle(inflatedRect); | 206 caretPainter->repaintRectangle(inflatedRect); |
194 } | 207 } |
195 | 208 |
196 bool CaretBase::shouldRepaintCaret(const RenderView* view, bool isContentEditabl
e) const | 209 bool CaretBase::shouldRepaintCaret(const RenderView* view, bool isContentEditabl
e) const |
197 { | 210 { |
198 ASSERT(view); | 211 ASSERT(view); |
199 bool caretBrowsing = false; | 212 bool caretBrowsing = false; |
200 if (FrameView* frameView = view->frameView()) { | 213 if (FrameView* frameView = view->frameView()) { |
201 LocalFrame& frame = frameView->frame(); // The frame where the selection
started | 214 LocalFrame& frame = frameView->frame(); // The frame where the selection
started |
202 caretBrowsing = frame.settings() && frame.settings()->caretBrowsingEnabl
ed(); | 215 caretBrowsing = frame.settings() && frame.settings()->caretBrowsingEnabl
ed(); |
(...skipping 13 matching lines...) Expand all Loading... |
216 // it happens after the document has accounted for any editing | 229 // it happens after the document has accounted for any editing |
217 // changes which may have been done. | 230 // changes which may have been done. |
218 // And, we need to leave this layout here so the caret moves right | 231 // And, we need to leave this layout here so the caret moves right |
219 // away after clicking. | 232 // away after clicking. |
220 m_caretRectNeedsUpdate = true; | 233 m_caretRectNeedsUpdate = true; |
221 | 234 |
222 if (caretRectChanged) | 235 if (caretRectChanged) |
223 return; | 236 return; |
224 | 237 |
225 if (RenderView* view = node->document().renderView()) { | 238 if (RenderView* view = node->document().renderView()) { |
226 if (shouldRepaintCaret(view, node->isContentEditable(Node::UserSelectAll
IsAlwaysNonEditable))) | 239 if (shouldRepaintCaret(view, node->isContentEditable(Node::UserSelectAll
IsAlwaysNonEditable))) { |
227 repaintCaretForLocalRect(node, localCaretRectWithoutUpdate()); | 240 LayoutRect drawingRect = localCaretRectWithoutUpdate(); |
| 241 updateDirectionPointer(caretRenderer(node), drawingRect); |
| 242 repaintCaretForLocalRect(node, drawingRect); |
| 243 } |
228 } | 244 } |
229 } | 245 } |
230 | 246 |
231 void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi
nt& paintOffset, const LayoutRect& clipRect) const | 247 void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi
nt& paintOffset, const LayoutRect& clipRect) const |
232 { | 248 { |
233 if (m_caretVisibility == Hidden) | 249 if (m_caretVisibility == Hidden) |
234 return; | 250 return; |
235 | 251 |
236 LayoutRect drawingRect = localCaretRectWithoutUpdate(); | 252 LayoutRect drawingRect = localCaretRectWithoutUpdate(); |
237 RenderObject* renderer = caretRenderer(node); | 253 RenderObject* renderer = caretRenderer(node); |
238 if (renderer && renderer->isBox()) | 254 if (renderer && renderer->isBox()) |
239 toRenderBox(renderer)->flipForWritingMode(drawingRect); | 255 toRenderBox(renderer)->flipForWritingMode(drawingRect); |
240 drawingRect.moveBy(roundedIntPoint(paintOffset)); | 256 drawingRect.moveBy(roundedIntPoint(paintOffset)); |
241 LayoutRect caret = intersection(drawingRect, clipRect); | 257 LayoutRect caret = intersection(drawingRect, clipRect); |
242 if (caret.isEmpty()) | 258 if (caret.isEmpty()) |
243 return; | 259 return; |
244 | 260 |
| 261 TextDirection containerDirection = toRenderBoxModelObject(renderer)->style()
->direction(); |
| 262 LayoutRect directionPointerCaret = caret; |
| 263 |
| 264 // Drawing different Caret which shows editing style similar to IE. |
| 265 if (containerDirection == LTR) |
| 266 directionPointerCaret.setX(directionPointerCaret.x() + 1); |
| 267 else |
| 268 directionPointerCaret.setX(directionPointerCaret.x() - 2); |
| 269 |
| 270 directionPointerCaret.setWidth(LayoutUnit(2)); |
| 271 directionPointerCaret.setHeight(LayoutUnit(1)); |
| 272 |
245 Color caretColor = Color::black; | 273 Color caretColor = Color::black; |
246 | 274 |
247 Element* element; | 275 Element* element; |
248 if (node->isElementNode()) | 276 if (node->isElementNode()) |
249 element = toElement(node); | 277 element = toElement(node); |
250 else | 278 else |
251 element = node->parentElement(); | 279 element = node->parentElement(); |
252 | 280 |
253 if (element && element->renderer()) | 281 if (element && element->renderer()) |
254 caretColor = element->renderer()->resolveColor(CSSPropertyColor); | 282 caretColor = element->renderer()->resolveColor(CSSPropertyColor); |
255 | 283 |
256 context->fillRect(caret, caretColor); | 284 context->fillRect(caret, caretColor); |
| 285 context->fillRect(directionPointerCaret, caretColor); |
| 286 |
| 287 // Update directionPointerCaret points and lets draw one more small rect to
match IE. |
| 288 directionPointerCaret.setY(caret.y() + LayoutUnit(1)); |
| 289 directionPointerCaret.setWidth(LayoutUnit(1)); |
| 290 if (containerDirection == RTL) |
| 291 directionPointerCaret.setX(directionPointerCaret.x() + 1); |
| 292 context->fillRect(directionPointerCaret, caretColor); |
257 } | 293 } |
258 | 294 |
259 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p,
const LayoutPoint& paintOffset, const LayoutRect& clipRect) const | 295 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p,
const LayoutPoint& paintOffset, const LayoutRect& clipRect) const |
260 { | 296 { |
261 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram
e) | 297 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram
e) |
262 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset,
clipRect); | 298 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset,
clipRect); |
263 } | 299 } |
264 | 300 |
265 } | 301 } |
OLD | NEW |