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

Unified Diff: third_party/WebKit/WebCore/editing/Selection.h

Issue 21184: WebKit merge 40722:40785 (part 1) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 10 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
Index: third_party/WebKit/WebCore/editing/Selection.h
===================================================================
--- third_party/WebKit/WebCore/editing/Selection.h (revision 9391)
+++ third_party/WebKit/WebCore/editing/Selection.h (working copy)
@@ -37,8 +37,7 @@
class Selection {
public:
- enum EState { NONE, CARET, RANGE };
- enum EDirection { FORWARD, BACKWARD, RIGHT, LEFT };
+ enum SelectionType { NoSelection, CaretSelection, RangeSelection };
Selection();
@@ -52,7 +51,7 @@
static Selection selectionFromContentsOfNode(Node*);
- EState state() const { return m_state; }
+ SelectionType selectionType() const { return m_selectionType; }
void setAffinity(EAffinity affinity) { m_affinity = affinity; }
EAffinity affinity() const { return m_affinity; }
@@ -63,17 +62,17 @@
void setExtent(const VisiblePosition&);
Position base() const { return m_base; }
- Position extent() const { return m_extent; }
+ Position extent() const { return m_extent; }
Position start() const { return m_start; }
Position end() const { return m_end; }
VisiblePosition visibleStart() const { return VisiblePosition(m_start, isRange() ? DOWNSTREAM : affinity()); }
VisiblePosition visibleEnd() const { return VisiblePosition(m_end, isRange() ? UPSTREAM : affinity()); }
- bool isNone() const { return state() == NONE; }
- bool isCaret() const { return state() == CARET; }
- bool isRange() const { return state() == RANGE; }
- bool isCaretOrRange() const { return state() != NONE; }
+ bool isNone() const { return selectionType() == NoSelection; }
+ bool isCaret() const { return selectionType() == CaretSelection; }
+ bool isRange() const { return selectionType() == RangeSelection; }
+ bool isCaretOrRange() const { return selectionType() != NoSelection; }
bool isBaseFirst() const { return m_baseIsFirst; }
@@ -82,7 +81,13 @@
bool expandUsingGranularity(TextGranularity granularity);
TextGranularity granularity() const { return m_granularity; }
- PassRefPtr<Range> toRange() const;
+ // We don't yet support multi-range selections, so we only ever have one range to return.
+ PassRefPtr<Range> firstRange() const;
+
+ // FIXME: Most callers probably don't want this function, but are using it
+ // for historical reasons. toNormalizedRange contracts the range around
+ // text, and moves the caret upstream before returning the range.
+ PassRefPtr<Range> toNormalizedRange() const;
Element* rootEditableElement() const;
bool isContentEditable() const;
@@ -100,18 +105,23 @@
private:
void validate();
- void adjustForEditableContent();
- Position m_base; // base position for the selection
- Position m_extent; // extent position for the selection
- Position m_start; // start position for the selection
- Position m_end; // end position for the selection
+ // Support methods for validate()
+ void setBaseAndExtentToDeepEquivalents();
+ void setStartAndEndFromBaseAndExtentRespectingGranularity();
+ void adjustSelectionToAvoidCrossingEditingBoundaries();
+ void updateSelectionType();
- EAffinity m_affinity; // the upstream/downstream affinity of the caret
- TextGranularity m_granularity; // granularity of start/end selection
+ Position m_base; // Where the first click happened
+ Position m_extent; // Where the end click happened
+ Position m_start; // Leftmost position when expanded to respect granularity
+ Position m_end; // Rightmost position when expanded to respect granularity
+ EAffinity m_affinity; // the upstream/downstream affinity of the caret
+ TextGranularity m_granularity; // granularity of start/end selection
+
// these are cached, can be recalculated by validate()
- EState m_state; // the state of the selection
+ SelectionType m_selectionType; // None, Caret, Range
bool m_baseIsFirst; // true if base is before the extent
};
« no previous file with comments | « third_party/WebKit/WebCore/editing/ReplaceSelectionCommand.cpp ('k') | third_party/WebKit/WebCore/editing/Selection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698