Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / editing / FrameSelection.h
index 7e88d9f..d4eefe5 100644 (file)
@@ -39,7 +39,7 @@
 namespace WebCore {
 
 class CharacterData;
-class Frame;
+class LocalFrame;
 class GraphicsContext;
 class HTMLFormElement;
 class MutableStylePropertySet;
@@ -56,7 +56,7 @@ enum RevealExtentOption {
     DoNotRevealExtent
 };
 
-class FrameSelection : private CaretBase {
+class FrameSelection FINAL : public VisibleSelection::ChangeObserver, private CaretBase {
     WTF_MAKE_NONCOPYABLE(FrameSelection);
     WTF_MAKE_FAST_ALLOCATED;
 public:
@@ -77,7 +77,8 @@ public:
         return static_cast<EUserTriggered>(options & UserTriggered);
     }
 
-    explicit FrameSelection(Frame* = 0);
+    explicit FrameSelection(LocalFrame* = 0);
+    virtual ~FrameSelection();
 
     Element* rootEditableElement() const { return m_selection.rootEditableElement(); }
     Element* rootEditableElementOrDocumentElement() const;
@@ -94,7 +95,7 @@ public:
     const VisibleSelection& selection() const { return m_selection; }
     void setSelection(const VisibleSelection&, SetSelectionOptions = CloseTyping | ClearTypingStyle, CursorAlignOnScroll = AlignCursorOnScrollIfNeeded, TextGranularity = CharacterGranularity);
     void setSelection(const VisibleSelection& selection, TextGranularity granularity) { setSelection(selection, CloseTyping | ClearTypingStyle, AlignCursorOnScrollIfNeeded, granularity); }
-    bool setSelectedRange(Range*, EAffinity, bool closeTyping);
+    bool setSelectedRange(Range*, EAffinity, SetSelectionOptions = CloseTyping | ClearTypingStyle);
     void selectAll();
     void clear();
     void prepareForDestruction();
@@ -144,7 +145,11 @@ public:
     bool isCaretOrRange() const { return m_selection.isCaretOrRange(); }
     bool isInPasswordField() const;
 
-    PassRefPtr<Range> toNormalizedRange() const { return m_selection.toNormalizedRange(); }
+    // If this FrameSelection has a logical range which is still valid, this function return its clone. Otherwise,
+    // the return value from underlying VisibleSelection's firstRange() is returned.
+    PassRefPtrWillBeRawPtr<Range> firstRange() const;
+
+    PassRefPtrWillBeRawPtr<Range> toNormalizedRange() const { return m_selection.toNormalizedRange(); }
 
     void nodeWillBeRemoved(Node&);
     void didUpdateCharacterData(CharacterData*, unsigned offset, unsigned oldLength, unsigned newLength);
@@ -197,6 +202,9 @@ public:
 
     void setShouldShowBlockCursor(bool);
 
+    // VisibleSelection::ChangeObserver interface.
+    virtual void didChangeVisibleSelection() OVERRIDE;
+
 private:
     enum EPositionType { START, END, BASE, EXTENT };
 
@@ -235,14 +243,23 @@ private:
 
     void updateSelectionIfNeeded(const Position& base, const Position& extent, const Position& start, const Position& end);
 
-    Frame* m_frame;
+    void startObservingVisibleSelectionChange();
+    void stopObservingVisibleSelectionChangeIfNecessary();
+
+    LocalFrame* m_frame;
 
     LayoutUnit m_xPosForVerticalArrowNavigation;
 
     VisibleSelection m_selection;
+    bool m_observingVisibleSelection;
     VisiblePosition m_originalBase; // Used to store base before the adjustment at bidi boundary
     TextGranularity m_granularity;
 
+    // The range specified by the user, which may not be visually canonicalized (hence "logical").
+    // This will be invalidated if the underlying VisibleSelection changes. If that happens, this variable will
+    // become null, in which case logical positions == visible positions.
+    RefPtrWillBePersistent<Range> m_logicalRange;
+
     RefPtr<Node> m_previousCaretNode; // The last node which painted the caret. Retained for clearing the old caret when it moves.
 
     RefPtr<EditingStyle> m_typingStyle;