| OLD | NEW |
| 1 /* | 1 /* |
| 2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 2000 Dirk Mueller (mueller@kde.org) | 3 * (C) 2000 Dirk Mueller (mueller@kde.org) |
| 4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. | 4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
| 5 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) | 5 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) |
| 6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) | 6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 } | 231 } |
| 232 | 232 |
| 233 static FloatRect localQuadForTextBox(InlineTextBox* box, unsigned start, unsigne
d end, bool useSelectionHeight) | 233 static FloatRect localQuadForTextBox(InlineTextBox* box, unsigned start, unsigne
d end, bool useSelectionHeight) |
| 234 { | 234 { |
| 235 unsigned realEnd = std::min(box->end() + 1, end); | 235 unsigned realEnd = std::min(box->end() + 1, end); |
| 236 LayoutRect r = box->localSelectionRect(start, realEnd); | 236 LayoutRect r = box->localSelectionRect(start, realEnd); |
| 237 if (r.height()) { | 237 if (r.height()) { |
| 238 if (!useSelectionHeight) { | 238 if (!useSelectionHeight) { |
| 239 // Change the height and y position (or width and x for vertical tex
t) | 239 // Change the height and y position (or width and x for vertical tex
t) |
| 240 // because selectionRect uses selection-specific values. | 240 // because selectionRect uses selection-specific values. |
| 241 if (box->isHorizontal()) { | 241 r.setHeight(box->height()); |
| 242 r.setHeight(box->height()); | 242 r.setY(box->y()); |
| 243 r.setY(box->y()); | |
| 244 } else { | |
| 245 r.setWidth(box->width()); | |
| 246 r.setX(box->x()); | |
| 247 } | |
| 248 } | 243 } |
| 249 return FloatRect(r); | 244 return FloatRect(r); |
| 250 } | 245 } |
| 251 return FloatRect(); | 246 return FloatRect(); |
| 252 } | 247 } |
| 253 | 248 |
| 254 void RenderText::absoluteRectsForRange(Vector<IntRect>& rects, unsigned start, u
nsigned end, bool useSelectionHeight) | 249 void RenderText::absoluteRectsForRange(Vector<IntRect>& rects, unsigned start, u
nsigned end, bool useSelectionHeight) |
| 255 { | 250 { |
| 256 // Work around signed/unsigned issues. This function takes unsigneds, and is
often passed UINT_MAX | 251 // Work around signed/unsigned issues. This function takes unsigneds, and is
often passed UINT_MAX |
| 257 // to mean "all the way to the end". InlineTextBox coordinates are unsigneds
, so changing this | 252 // to mean "all the way to the end". InlineTextBox coordinates are unsigneds
, so changing this |
| 258 // function to take ints causes various internal mismatches. But selectionRe
ct takes ints, and | 253 // function to take ints causes various internal mismatches. But selectionRe
ct takes ints, and |
| 259 // passing UINT_MAX to it causes trouble. Ideally we'd change selectionRect
to take unsigneds, but | 254 // passing UINT_MAX to it causes trouble. Ideally we'd change selectionRect
to take unsigneds, but |
| 260 // that would cause many ripple effects, so for now we'll just clamp our uns
igned parameters to INT_MAX. | 255 // that would cause many ripple effects, so for now we'll just clamp our uns
igned parameters to INT_MAX. |
| 261 ASSERT(end == UINT_MAX || end <= INT_MAX); | 256 ASSERT(end == UINT_MAX || end <= INT_MAX); |
| 262 ASSERT(start <= INT_MAX); | 257 ASSERT(start <= INT_MAX); |
| 263 start = std::min(start, static_cast<unsigned>(INT_MAX)); | 258 start = std::min(start, static_cast<unsigned>(INT_MAX)); |
| 264 end = std::min(end, static_cast<unsigned>(INT_MAX)); | 259 end = std::min(end, static_cast<unsigned>(INT_MAX)); |
| 265 | 260 |
| 266 for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) { | 261 for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) { |
| 267 // Note: box->end() returns the index of the last character, not the ind
ex past it | 262 // Note: box->end() returns the index of the last character, not the ind
ex past it |
| 268 if (start <= box->start() && box->end() < end) { | 263 if (start <= box->start() && box->end() < end) { |
| 269 FloatRect r = box->calculateBoundaries(); | 264 FloatRect r = box->calculateBoundaries(); |
| 270 if (useSelectionHeight) { | 265 if (useSelectionHeight) { |
| 271 LayoutRect selectionRect = box->localSelectionRect(start, end); | 266 LayoutRect selectionRect = box->localSelectionRect(start, end); |
| 272 if (box->isHorizontal()) { | 267 r.setHeight(selectionRect.height().toFloat()); |
| 273 r.setHeight(selectionRect.height().toFloat()); | 268 r.setY(selectionRect.y().toFloat()); |
| 274 r.setY(selectionRect.y().toFloat()); | |
| 275 } else { | |
| 276 r.setWidth(selectionRect.width().toFloat()); | |
| 277 r.setX(selectionRect.x().toFloat()); | |
| 278 } | |
| 279 } | 269 } |
| 280 rects.append(localToAbsoluteQuad(r, 0).enclosingBoundingBox()); | 270 rects.append(localToAbsoluteQuad(r, 0).enclosingBoundingBox()); |
| 281 } else { | 271 } else { |
| 282 // FIXME: This code is wrong. It's converting local to absolute twic
e. http://webkit.org/b/65722 | 272 // FIXME: This code is wrong. It's converting local to absolute twic
e. http://webkit.org/b/65722 |
| 283 FloatRect rect = localQuadForTextBox(box, start, end, useSelectionHe
ight); | 273 FloatRect rect = localQuadForTextBox(box, start, end, useSelectionHe
ight); |
| 284 if (!rect.isZero()) | 274 if (!rect.isZero()) |
| 285 rects.append(localToAbsoluteQuad(rect, 0).enclosingBoundingBox()
); | 275 rects.append(localToAbsoluteQuad(rect, 0).enclosingBoundingBox()
); |
| 286 } | 276 } |
| 287 } | 277 } |
| 288 } | 278 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 ASSERT(start <= INT_MAX); | 332 ASSERT(start <= INT_MAX); |
| 343 start = std::min(start, static_cast<unsigned>(INT_MAX)); | 333 start = std::min(start, static_cast<unsigned>(INT_MAX)); |
| 344 end = std::min(end, static_cast<unsigned>(INT_MAX)); | 334 end = std::min(end, static_cast<unsigned>(INT_MAX)); |
| 345 | 335 |
| 346 for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) { | 336 for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) { |
| 347 // Note: box->end() returns the index of the last character, not the ind
ex past it | 337 // Note: box->end() returns the index of the last character, not the ind
ex past it |
| 348 if (start <= box->start() && box->end() < end) { | 338 if (start <= box->start() && box->end() < end) { |
| 349 FloatRect r = box->calculateBoundaries(); | 339 FloatRect r = box->calculateBoundaries(); |
| 350 if (useSelectionHeight) { | 340 if (useSelectionHeight) { |
| 351 LayoutRect selectionRect = box->localSelectionRect(start, end); | 341 LayoutRect selectionRect = box->localSelectionRect(start, end); |
| 352 if (box->isHorizontal()) { | 342 r.setHeight(selectionRect.height().toFloat()); |
| 353 r.setHeight(selectionRect.height().toFloat()); | 343 r.setY(selectionRect.y().toFloat()); |
| 354 r.setY(selectionRect.y().toFloat()); | |
| 355 } else { | |
| 356 r.setWidth(selectionRect.width().toFloat()); | |
| 357 r.setX(selectionRect.x().toFloat()); | |
| 358 } | |
| 359 } | 344 } |
| 360 quads.append(localToAbsoluteQuad(r, 0)); | 345 quads.append(localToAbsoluteQuad(r, 0)); |
| 361 } else { | 346 } else { |
| 362 FloatRect rect = localQuadForTextBox(box, start, end, useSelectionHe
ight); | 347 FloatRect rect = localQuadForTextBox(box, start, end, useSelectionHe
ight); |
| 363 if (!rect.isZero()) | 348 if (!rect.isZero()) |
| 364 quads.append(localToAbsoluteQuad(rect, 0)); | 349 quads.append(localToAbsoluteQuad(rect, 0)); |
| 365 } | 350 } |
| 366 } | 351 } |
| 367 } | 352 } |
| 368 | 353 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 } | 477 } |
| 493 | 478 |
| 494 return createPositionWithAffinityForBox(box, box->caretLeftmostOffset(), sho
uldAffinityBeDownstream); | 479 return createPositionWithAffinityForBox(box, box->caretLeftmostOffset(), sho
uldAffinityBeDownstream); |
| 495 } | 480 } |
| 496 | 481 |
| 497 PositionWithAffinity RenderText::positionForPoint(const LayoutPoint& point) | 482 PositionWithAffinity RenderText::positionForPoint(const LayoutPoint& point) |
| 498 { | 483 { |
| 499 if (!firstTextBox() || textLength() == 0) | 484 if (!firstTextBox() || textLength() == 0) |
| 500 return createPositionWithAffinity(0, DOWNSTREAM); | 485 return createPositionWithAffinity(0, DOWNSTREAM); |
| 501 | 486 |
| 502 LayoutUnit pointLineDirection = firstTextBox()->isHorizontal() ? point.x() :
point.y(); | 487 LayoutUnit pointLineDirection = point.x(); |
| 503 LayoutUnit pointBlockDirection = firstTextBox()->isHorizontal() ? point.y()
: point.x(); | 488 LayoutUnit pointBlockDirection = point.y(); |
| 504 | 489 |
| 505 InlineTextBox* lastBox = 0; | 490 InlineTextBox* lastBox = 0; |
| 506 for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) { | 491 for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) { |
| 507 if (box->isLineBreak() && !box->prevLeafChild() && box->nextLeafChild()
&& !box->nextLeafChild()->isLineBreak()) | 492 if (box->isLineBreak() && !box->prevLeafChild() && box->nextLeafChild()
&& !box->nextLeafChild()->isLineBreak()) |
| 508 box = box->nextTextBox(); | 493 box = box->nextTextBox(); |
| 509 | 494 |
| 510 RootInlineBox& rootBox = box->root(); | 495 RootInlineBox& rootBox = box->root(); |
| 511 LayoutUnit top = std::min(rootBox.selectionTop(), rootBox.lineTop()); | 496 LayoutUnit top = std::min(rootBox.selectionTop(), rootBox.lineTop()); |
| 512 if (pointBlockDirection > top || pointBlockDirection == top) { | 497 if (pointBlockDirection > top || pointBlockDirection == top) { |
| 513 LayoutUnit bottom = rootBox.selectionBottom(); | 498 LayoutUnit bottom = rootBox.selectionBottom(); |
| (...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1665 ASSERT(child->prevTextBox() == prev); | 1650 ASSERT(child->prevTextBox() == prev); |
| 1666 prev = child; | 1651 prev = child; |
| 1667 } | 1652 } |
| 1668 ASSERT(prev == m_lastTextBox); | 1653 ASSERT(prev == m_lastTextBox); |
| 1669 #endif | 1654 #endif |
| 1670 } | 1655 } |
| 1671 | 1656 |
| 1672 #endif | 1657 #endif |
| 1673 | 1658 |
| 1674 } // namespace blink | 1659 } // namespace blink |
| OLD | NEW |