1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef LineLayoutItem_h
#define LineLayoutItem_h
#include "core/layout/LayoutObject.h"
#include "core/layout/LayoutObjectInlines.h"
#include "core/layout/LayoutText.h"
#include "core/paint/ObjectPaintInvalidator.h"
#include "platform/LayoutUnit.h"
#include "wtf/Allocator.h"
#include "wtf/HashTableDeletedValueType.h"
namespace blink {
class ComputedStyle;
class Document;
class HitTestRequest;
class HitTestLocation;
class LayoutObject;
class LineLayoutBox;
class LineLayoutBoxModel;
class LineLayoutAPIShim;
enum HitTestFilter;
static LayoutObject* const kHashTableDeletedValue =
reinterpret_cast<LayoutObject*>(-1);
class LineLayoutItem {
DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
public:
explicit LineLayoutItem(LayoutObject* layoutObject)
: m_layoutObject(layoutObject) {}
explicit LineLayoutItem(WTF::HashTableDeletedValueType)
: m_layoutObject(kHashTableDeletedValue) {}
LineLayoutItem(std::nullptr_t) : m_layoutObject(0) {}
LineLayoutItem() : m_layoutObject(0) {}
explicit operator bool() const { return m_layoutObject; }
bool isEqual(const LayoutObject* layoutObject) const {
return m_layoutObject == layoutObject;
}
bool operator==(const LineLayoutItem& other) const {
return m_layoutObject == other.m_layoutObject;
}
bool operator!=(const LineLayoutItem& other) const {
return !(*this == other);
}
String debugName() const { return m_layoutObject->debugName(); }
bool needsLayout() const { return m_layoutObject->needsLayout(); }
Node* node() const { return m_layoutObject->node(); }
Node* nonPseudoNode() const { return m_layoutObject->nonPseudoNode(); }
LineLayoutItem parent() const {
return LineLayoutItem(m_layoutObject->parent());
}
// Implemented in LineLayoutBox.h
// Intentionally returns a LineLayoutBox to avoid exposing LayoutBlock
// to the line layout code.
LineLayoutBox containingBlock() const;
// Implemented in LineLayoutBoxModel.h
// Intentionally returns a LineLayoutBoxModel to avoid exposing
// LayoutBoxModelObject to the line layout code.
LineLayoutBoxModel enclosingBoxModelObject() const;
LineLayoutItem container() const {
return LineLayoutItem(m_layoutObject->container());
}
bool isDescendantOf(const LineLayoutItem item) const {
return m_layoutObject->isDescendantOf(item.m_layoutObject);
}
void updateHitTestResult(HitTestResult& result, const LayoutPoint& point) {
return m_layoutObject->updateHitTestResult(result, point);
}
LineLayoutItem nextSibling() const {
return LineLayoutItem(m_layoutObject->nextSibling());
}
LineLayoutItem previousSibling() const {
return LineLayoutItem(m_layoutObject->previousSibling());
}
LineLayoutItem slowFirstChild() const {
return LineLayoutItem(m_layoutObject->slowFirstChild());
}
LineLayoutItem slowLastChild() const {
return LineLayoutItem(m_layoutObject->slowLastChild());
}
// TODO(dgrogan/eae): Collapse these 4 methods to 1. Settle on pointer or
// ref. Give firstLine a default value.
const ComputedStyle* style() const { return m_layoutObject->style(); }
const ComputedStyle& styleRef() const { return m_layoutObject->styleRef(); }
const ComputedStyle* style(bool firstLine) const {
return m_layoutObject->style(firstLine);
}
const ComputedStyle& styleRef(bool firstLine) const {
return m_layoutObject->styleRef(firstLine);
}
Document& document() const { return m_layoutObject->document(); }
// TODO(dgrogan): This is the only caller: move the logic from LayoutObject
// to here.
bool preservesNewline() const { return m_layoutObject->preservesNewline(); }
unsigned length() const { return m_layoutObject->length(); }
void dirtyLinesFromChangedChild(
LineLayoutItem item,
MarkingBehavior markingBehaviour = MarkContainerChain) const {
m_layoutObject->dirtyLinesFromChangedChild(item.layoutObject(),
markingBehaviour);
}
bool ancestorLineBoxDirty() const {
return m_layoutObject->ancestorLineBoxDirty();
}
// TODO(dgrogan/eae): Remove this method and replace every call with an ||.
bool isFloatingOrOutOfFlowPositioned() const {
return m_layoutObject->isFloatingOrOutOfFlowPositioned();
}
bool isFloating() const { return m_layoutObject->isFloating(); }
bool isOutOfFlowPositioned() const {
return m_layoutObject->isOutOfFlowPositioned();
}
bool isBox() const { return m_layoutObject->isBox(); }
bool isBoxModelObject() const { return m_layoutObject->isBoxModelObject(); }
bool isBR() const { return m_layoutObject->isBR(); }
bool isCombineText() const { return m_layoutObject->isCombineText(); }
bool isHorizontalWritingMode() const {
return m_layoutObject->isHorizontalWritingMode();
}
bool isImage() const { return m_layoutObject->isImage(); }
bool isInline() const { return m_layoutObject->isInline(); }
bool isInlineBlockOrInlineTable() const {
return m_layoutObject->isInlineBlockOrInlineTable();
}
bool isInlineElementContinuation() const {
return m_layoutObject->isInlineElementContinuation();
}
// TODO(dgrogan/eae): Replace isType with an enum in the API? As it stands
// we mix isProperty and isType, which is confusing.
bool isLayoutBlock() const { return m_layoutObject->isLayoutBlock(); }
bool isLayoutBlockFlow() const { return m_layoutObject->isLayoutBlockFlow(); }
bool isLayoutInline() const { return m_layoutObject->isLayoutInline(); }
bool isListMarker() const { return m_layoutObject->isListMarker(); }
bool isAtomicInlineLevel() const {
return m_layoutObject->isAtomicInlineLevel();
}
bool isRubyText() const { return m_layoutObject->isRubyText(); }
bool isRubyRun() const { return m_layoutObject->isRubyRun(); }
bool isRubyBase() const { return m_layoutObject->isRubyBase(); }
bool isSVGInline() const { return m_layoutObject->isSVGInline(); }
bool isSVGInlineText() const { return m_layoutObject->isSVGInlineText(); }
bool isSVGText() const { return m_layoutObject->isSVGText(); }
bool isSVGTextPath() const { return m_layoutObject->isSVGTextPath(); }
bool isTableCell() const { return m_layoutObject->isTableCell(); }
bool isText() const { return m_layoutObject->isText(); }
bool isEmptyText() const {
return isText() && toLayoutText(m_layoutObject)->text().isEmpty();
}
bool hasLayer() const { return m_layoutObject->hasLayer(); }
bool selfNeedsLayout() const { return m_layoutObject->selfNeedsLayout(); }
// TODO(dgrogan/eae): Why does layoutObject need to know if its ancestor
// line box is dirty at all?
void setAncestorLineBoxDirty() const {
m_layoutObject->setAncestorLineBoxDirty();
}
int caretMinOffset() const { return m_layoutObject->caretMinOffset(); }
int caretMaxOffset() const { return m_layoutObject->caretMaxOffset(); }
bool hasFlippedBlocksWritingMode() const {
return m_layoutObject->hasFlippedBlocksWritingMode();
}
bool visibleToHitTestRequest(const HitTestRequest& request) const {
return m_layoutObject->visibleToHitTestRequest(request);
}
bool hitTest(HitTestResult& result,
const HitTestLocation& locationInContainer,
const LayoutPoint& accumulatedOffset,
HitTestFilter filter = HitTestAll) {
return m_layoutObject->hitTest(result, locationInContainer,
accumulatedOffset, filter);
}
SelectionState getSelectionState() const {
return m_layoutObject->getSelectionState();
}
// TODO(dgrogan/eae): Can we move this to style?
Color selectionBackgroundColor() const {
return m_layoutObject->selectionBackgroundColor();
}
// TODO(dgrogan/eae): Needed for Color::current. Can we move this somewhere?
Color resolveColor(const ComputedStyle& styleToUse, int colorProperty) {
return m_layoutObject->resolveColor(styleToUse, colorProperty);
}
bool isInFlowPositioned() const {
return m_layoutObject->isInFlowPositioned();
}
// TODO(dgrogan/eae): Can we change this to GlobalToLocal and vice versa
// instead of having 4 methods? See localToAbsoluteQuad below.
PositionWithAffinity positionForPoint(const LayoutPoint& point) {
return m_layoutObject->positionForPoint(point);
}
PositionWithAffinity createPositionWithAffinity(int offset,
TextAffinity affinity) {
return m_layoutObject->createPositionWithAffinity(offset, affinity);
}
LineLayoutItem previousInPreOrder(const LayoutObject* stayWithin) const {
return LineLayoutItem(m_layoutObject->previousInPreOrder(stayWithin));
}
FloatQuad localToAbsoluteQuad(const FloatQuad& quad,
MapCoordinatesFlags mode = 0) const {
return m_layoutObject->localToAbsoluteQuad(quad, mode);
}
FloatPoint localToAbsolute(const FloatPoint& localPoint = FloatPoint(),
MapCoordinatesFlags flags = 0) const {
return m_layoutObject->localToAbsolute(localPoint, flags);
}
bool hasOverflowClip() const { return m_layoutObject->hasOverflowClip(); }
// TODO(dgrogan/eae): Can we instead add a TearDown method to the API
// instead of exposing this and other shutdown code to line layout?
bool documentBeingDestroyed() const {
return m_layoutObject->documentBeingDestroyed();
}
LayoutRect visualRect() const { return m_layoutObject->visualRect(); }
bool isHashTableDeletedValue() const {
return m_layoutObject == kHashTableDeletedValue;
}
void setShouldDoFullPaintInvalidation() {
m_layoutObject->setShouldDoFullPaintInvalidation();
}
void slowSetPaintingLayerNeedsRepaint() {
ObjectPaintInvalidator(*m_layoutObject).slowSetPaintingLayerNeedsRepaint();
}
struct LineLayoutItemHash {
STATIC_ONLY(LineLayoutItemHash);
static unsigned hash(const LineLayoutItem& key) {
return WTF::PtrHash<LayoutObject>::hash(key.m_layoutObject);
}
static bool equal(const LineLayoutItem& a, const LineLayoutItem& b) {
return WTF::PtrHash<LayoutObject>::equal(a.m_layoutObject,
b.m_layoutObject);
}
static const bool safeToCompareToEmptyOrDeleted = true;
};
#ifndef NDEBUG
const char* name() const { return m_layoutObject->name(); }
// Intentionally returns a void* to avoid exposing LayoutObject* to the line
// layout code.
void* debugPointer() const { return m_layoutObject; }
void showTreeForThis() const { m_layoutObject->showTreeForThis(); }
String decoratedName() const { return m_layoutObject->decoratedName(); }
#endif
protected:
LayoutObject* layoutObject() { return m_layoutObject; }
const LayoutObject* layoutObject() const { return m_layoutObject; }
private:
LayoutObject* m_layoutObject;
friend class LayoutBlockFlow;
friend class LineLayoutAPIShim;
friend class LineLayoutBlockFlow;
friend class LineLayoutBox;
friend class LineLayoutRubyRun;
};
} // namespace blink
namespace WTF {
template <>
struct DefaultHash<blink::LineLayoutItem> {
using Hash = blink::LineLayoutItem::LineLayoutItemHash;
};
template <>
struct HashTraits<blink::LineLayoutItem>
: SimpleClassHashTraits<blink::LineLayoutItem> {
STATIC_ONLY(HashTraits);
};
} // namespace WTF
#endif // LineLayoutItem_h
|