Chromium Code Reviews| 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 RenderBoxModelObject* renderBoxMode lObject, LayoutRect& rect) | |
| 183 { | |
| 184 // Extra rect are drawn, need to refresh more area. | |
| 185 TextDirection containerDirection = renderBoxModelObject->style()->direction( ); | |
|
Inactive
2014/05/27 13:10:45
Ok, so I looked this up a bit more. Why do you nee
h.joshi
2014/05/28 03:02:53
Yes, RenderObject will be enough here to get style
| |
| 186 rect.setWidth(rect.width() + LayoutUnit(2)); | |
| 187 if (containerDirection == RTL) | |
| 188 rect.setX(rect.x() - LayoutUnit(2)); | |
| 189 } | |
| 190 | |
| 182 void CaretBase::repaintCaretForLocalRect(Node* node, const LayoutRect& rect) | 191 void CaretBase::repaintCaretForLocalRect(Node* node, const LayoutRect& rect) |
| 183 { | 192 { |
| 184 RenderObject* caretPainter = caretRenderer(node); | 193 RenderObject* caretPainter = caretRenderer(node); |
| 185 if (!caretPainter) | 194 if (!caretPainter) |
| 186 return; | 195 return; |
| 187 | 196 |
| 188 // FIXME: Need to over-paint 1 pixel to workaround some rounding problems. | 197 // FIXME: Need to over-paint 1 pixel to workaround some rounding problems. |
| 189 // https://bugs.webkit.org/show_bug.cgi?id=108283 | 198 // https://bugs.webkit.org/show_bug.cgi?id=108283 |
| 190 LayoutRect inflatedRect = rect; | 199 LayoutRect inflatedRect = rect; |
| 191 inflatedRect.inflate(1); | 200 inflatedRect.inflate(1); |
| 192 | 201 |
| 202 updateDirectionPointer(toRenderBoxModelObject(caretPainter), inflatedRect); | |
|
Inactive
2014/05/27 13:10:45
This cast should not be needed. Also, I am still n
h.joshi
2014/05/28 03:02:53
Yes, will remove after changing method usage.
| |
| 193 caretPainter->repaintRectangle(inflatedRect); | 203 caretPainter->repaintRectangle(inflatedRect); |
| 194 } | 204 } |
| 195 | 205 |
| 196 bool CaretBase::shouldRepaintCaret(const RenderView* view, bool isContentEditabl e) const | 206 bool CaretBase::shouldRepaintCaret(const RenderView* view, bool isContentEditabl e) const |
| 197 { | 207 { |
| 198 ASSERT(view); | 208 ASSERT(view); |
| 199 bool caretBrowsing = false; | 209 bool caretBrowsing = false; |
| 200 if (FrameView* frameView = view->frameView()) { | 210 if (FrameView* frameView = view->frameView()) { |
| 201 LocalFrame& frame = frameView->frame(); // The frame where the selection started | 211 LocalFrame& frame = frameView->frame(); // The frame where the selection started |
| 202 caretBrowsing = frame.settings() && frame.settings()->caretBrowsingEnabl ed(); | 212 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 | 226 // it happens after the document has accounted for any editing |
| 217 // changes which may have been done. | 227 // changes which may have been done. |
| 218 // And, we need to leave this layout here so the caret moves right | 228 // And, we need to leave this layout here so the caret moves right |
| 219 // away after clicking. | 229 // away after clicking. |
| 220 m_caretRectNeedsUpdate = true; | 230 m_caretRectNeedsUpdate = true; |
| 221 | 231 |
| 222 if (caretRectChanged) | 232 if (caretRectChanged) |
| 223 return; | 233 return; |
| 224 | 234 |
| 225 if (RenderView* view = node->document().renderView()) { | 235 if (RenderView* view = node->document().renderView()) { |
| 226 if (shouldRepaintCaret(view, node->isContentEditable(Node::UserSelectAll IsAlwaysNonEditable))) | 236 if (shouldRepaintCaret(view, node->isContentEditable(Node::UserSelectAll IsAlwaysNonEditable))) { |
| 227 repaintCaretForLocalRect(node, localCaretRectWithoutUpdate()); | 237 LayoutRect drawingRect = localCaretRectWithoutUpdate(); |
| 238 updateDirectionPointer(toRenderBoxModelObject(caretRenderer(node)), drawingRect); | |
|
Inactive
2014/05/27 13:10:45
Ditto. Cast should not be needed.
Also, what if ca
h.joshi
2014/05/28 03:02:53
Ditto
| |
| 239 repaintCaretForLocalRect(node, drawingRect); | |
| 240 } | |
| 228 } | 241 } |
| 229 } | 242 } |
| 230 | 243 |
| 231 void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi nt& paintOffset, const LayoutRect& clipRect) const | 244 void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi nt& paintOffset, const LayoutRect& clipRect) const |
| 232 { | 245 { |
| 233 if (m_caretVisibility == Hidden) | 246 if (m_caretVisibility == Hidden) |
| 234 return; | 247 return; |
| 235 | 248 |
| 236 LayoutRect drawingRect = localCaretRectWithoutUpdate(); | 249 LayoutRect drawingRect = localCaretRectWithoutUpdate(); |
| 237 RenderObject* renderer = caretRenderer(node); | 250 RenderObject* renderer = caretRenderer(node); |
| 238 if (renderer && renderer->isBox()) | 251 if (renderer && renderer->isBox()) |
| 239 toRenderBox(renderer)->flipForWritingMode(drawingRect); | 252 toRenderBox(renderer)->flipForWritingMode(drawingRect); |
| 240 drawingRect.moveBy(roundedIntPoint(paintOffset)); | 253 drawingRect.moveBy(roundedIntPoint(paintOffset)); |
| 241 LayoutRect caret = intersection(drawingRect, clipRect); | 254 LayoutRect caret = intersection(drawingRect, clipRect); |
| 242 if (caret.isEmpty()) | 255 if (caret.isEmpty()) |
| 243 return; | 256 return; |
| 244 | 257 |
| 258 TextDirection containerDirection = toRenderBoxModelObject(renderer)->style() ->direction(); | |
|
Inactive
2014/05/27 13:10:45
Cast should not be needed.
h.joshi
2014/05/28 03:02:53
Yes, will make changes
| |
| 259 LayoutRect directionPointerCaret = caret; | |
| 260 | |
| 261 // Drawing different Caret which shows editing style similar to IE | |
|
Inactive
2014/05/27 13:10:45
nit: needs to end with a '.'
h.joshi
2014/05/28 03:02:53
Will make changes.
| |
| 262 if (containerDirection == LTR) | |
| 263 directionPointerCaret.setX(directionPointerCaret.x() + 1); | |
| 264 else | |
| 265 directionPointerCaret.setX(directionPointerCaret.x() - 2); | |
| 266 | |
| 267 directionPointerCaret.setWidth(LayoutUnit(2)); | |
| 268 directionPointerCaret.setHeight(LayoutUnit(1)); | |
| 269 | |
| 245 Color caretColor = Color::black; | 270 Color caretColor = Color::black; |
| 246 | 271 |
| 247 Element* element; | 272 Element* element; |
| 248 if (node->isElementNode()) | 273 if (node->isElementNode()) |
| 249 element = toElement(node); | 274 element = toElement(node); |
| 250 else | 275 else |
| 251 element = node->parentElement(); | 276 element = node->parentElement(); |
| 252 | 277 |
| 253 if (element && element->renderer()) | 278 if (element && element->renderer()) |
| 254 caretColor = element->renderer()->resolveColor(CSSPropertyColor); | 279 caretColor = element->renderer()->resolveColor(CSSPropertyColor); |
| 255 | 280 |
| 256 context->fillRect(caret, caretColor); | 281 context->fillRect(caret, caretColor); |
| 282 context->fillRect(directionPointerCaret, caretColor); | |
| 283 | |
| 284 // Update directionPointerCaret points and lets draw one more small rect to match IE. | |
| 285 directionPointerCaret.setY(caret.y() + LayoutUnit(1)); | |
| 286 directionPointerCaret.setWidth(LayoutUnit(1)); | |
| 287 if (containerDirection == RTL) | |
| 288 directionPointerCaret.setX(directionPointerCaret.x() + 1); | |
| 289 context->fillRect(directionPointerCaret, caretColor); | |
| 257 } | 290 } |
| 258 | 291 |
| 259 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p, const LayoutPoint& paintOffset, const LayoutRect& clipRect) const | 292 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p, const LayoutPoint& paintOffset, const LayoutRect& clipRect) const |
| 260 { | 293 { |
| 261 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram e) | 294 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram e) |
| 262 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset, clipRect); | 295 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset, clipRect); |
| 263 } | 296 } |
| 264 | 297 |
| 265 } | 298 } |
| OLD | NEW |