Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / editing / FrameSelection.h
index d4eefe5..01f2f87 100644 (file)
 #include "platform/Timer.h"
 #include "platform/geometry/IntRect.h"
 #include "platform/geometry/LayoutRect.h"
+#include "platform/heap/Handle.h"
 #include "wtf/Noncopyable.h"
 
-namespace WebCore {
+namespace blink {
 
 class CharacterData;
 class LocalFrame;
 class GraphicsContext;
 class HTMLFormElement;
-class MutableStylePropertySet;
-class RenderObject;
-class RenderView;
-class Settings;
 class Text;
 class VisiblePosition;
 
@@ -56,10 +53,17 @@ enum RevealExtentOption {
     DoNotRevealExtent
 };
 
-class FrameSelection FINAL : public VisibleSelection::ChangeObserver, private CaretBase {
+class FrameSelection final : public NoBaseWillBeGarbageCollectedFinalized<FrameSelection>, public VisibleSelection::ChangeObserver, private CaretBase {
     WTF_MAKE_NONCOPYABLE(FrameSelection);
-    WTF_MAKE_FAST_ALLOCATED;
+    WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
+    WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(FrameSelection);
 public:
+    static PassOwnPtrWillBeRawPtr<FrameSelection> create(LocalFrame* frame = nullptr)
+    {
+        return adoptPtrWillBeNoop(new FrameSelection(frame));
+    }
+    virtual ~FrameSelection();
+
     enum EAlteration { AlterationMove, AlterationExtend };
     enum CursorAlignOnScroll { AlignCursorOnScrollIfNeeded,
                                AlignCursorOnScrollAlways };
@@ -77,14 +81,20 @@ public:
         return static_cast<EUserTriggered>(options & UserTriggered);
     }
 
-    explicit FrameSelection(LocalFrame* = 0);
-    virtual ~FrameSelection();
+    enum DirectoinalOption {
+        NonDirectional,
+        Directional
+    };
+    enum ResetCaretBlinkOption {
+        None,
+        ResetCaretBlink
+    };
 
     Element* rootEditableElement() const { return m_selection.rootEditableElement(); }
     Element* rootEditableElementOrDocumentElement() const;
-    Node* rootEditableElementOrTreeScopeRootNode() const;
+    ContainerNode* rootEditableElementOrTreeScopeRootNode() const;
 
-    bool rendererIsEditable() const { return m_selection.rendererIsEditable(); }
+    bool hasEditableStyle() const { return m_selection.hasEditableStyle(); }
     bool isContentEditable() const { return m_selection.isContentEditable(); }
     bool isContentRichlyEditable() const { return m_selection.isContentRichlyEditable(); }
 
@@ -95,7 +105,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, SetSelectionOptions = CloseTyping | ClearTypingStyle);
+    bool setSelectedRange(Range*, EAffinity, DirectoinalOption directional = NonDirectional, SetSelectionOptions = CloseTyping | ClearTypingStyle);
     void selectAll();
     void clear();
     void prepareForDestruction();
@@ -127,14 +137,10 @@ public:
     Position end() const { return m_selection.end(); }
 
     // Return the renderer that is responsible for painting the caret (in the selection start node)
-    RenderObject* caretRenderer() const;
-
-    // Caret rect local to the caret's renderer
-    LayoutRect localCaretRect();
+    RenderBlock* caretRenderer() const;
 
     // Bounds of (possibly transformed) caret in absolute coords
     IntRect absoluteCaretBounds();
-    void setCaretRectNeedsUpdate() { CaretBase::setCaretRectNeedsUpdate(); }
 
     void didChangeFocus();
     void willBeModified(EAlteration, SelectionDirection);
@@ -144,6 +150,7 @@ public:
     bool isRange() const { return m_selection.isRange(); }
     bool isCaretOrRange() const { return m_selection.isCaretOrRange(); }
     bool isInPasswordField() const;
+    bool isDirectional() const { return m_selection.isDirectional(); }
 
     // 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.
@@ -156,10 +163,14 @@ public:
     void didMergeTextNodes(const Text& oldNode, unsigned offset);
     void didSplitTextNode(const Text& oldNode);
 
+    void updateAppearance(ResetCaretBlinkOption = None);
     void setCaretVisible(bool caretIsVisible) { setCaretVisibility(caretIsVisible ? Visible : Hidden); }
-    bool recomputeCaretRect();
+    bool isCaretBoundsDirty() const { return m_caretRectDirty; }
+    void setCaretRectNeedsUpdate();
+    void scheduleVisualUpdate() const;
     void invalidateCaretRect();
     void paintCaret(GraphicsContext*, const LayoutPoint&, const LayoutRect& clipRect);
+    bool ShouldPaintCaretForTesting() const { return m_shouldPaintCaret; }
 
     // Used to suspend caret blinking while the mouse is down.
     void setCaretBlinkingSuspended(bool suspended) { m_isCaretBlinkingSuspended = suspended; }
@@ -171,11 +182,11 @@ public:
     bool isFocusedAndActive() const;
     void pageActivationChanged();
 
-    // Painting.
-    void updateAppearance();
-
     void updateSecureKeyboardEntryIfActive();
 
+    // Returns true if a word is selected.
+    bool selectWordAroundPosition(const VisiblePosition&);
+
 #ifndef NDEBUG
     void formatForDebugger(char* buffer, unsigned length) const;
     void showTreeForThis() const;
@@ -187,13 +198,15 @@ public:
     void notifyRendererOfSelectionChange(EUserTriggered);
 
     EditingStyle* typingStyle() const;
-    void setTypingStyle(PassRefPtr<EditingStyle>);
+    void setTypingStyle(PassRefPtrWillBeRawPtr<EditingStyle>);
     void clearTypingStyle();
 
     String selectedText() const;
     String selectedTextForClipboard() const;
 
-    FloatRect bounds(bool clipToVisibleContent = true) const;
+    // The bounds are clipped to the viewport as this is what callers expect.
+    LayoutRect bounds() const;
+    LayoutRect unclippedBounds() const;
 
     HTMLFormElement* currentForm() const;
 
@@ -203,9 +216,13 @@ public:
     void setShouldShowBlockCursor(bool);
 
     // VisibleSelection::ChangeObserver interface.
-    virtual void didChangeVisibleSelection() OVERRIDE;
+    virtual void didChangeVisibleSelection() override;
+
+    virtual void trace(Visitor*) override;
 
 private:
+    explicit FrameSelection(LocalFrame*);
+
     enum EPositionType { START, END, BASE, EXTENT };
 
     void respondToNodeModification(Node&, bool baseRemoved, bool extentRemoved, bool startRemoved, bool endRemoved);
@@ -229,6 +246,8 @@ private:
     LayoutUnit lineDirectionPointForBlockDirectionNavigation(EPositionType);
 
     void notifyAccessibilityForSelectionChange();
+    void notifyCompositorForSelectionChange();
+    void notifyEventHandlerForSelectionChange();
 
     void focusedOrActiveStateChanged();
 
@@ -246,7 +265,9 @@ private:
     void startObservingVisibleSelectionChange();
     void stopObservingVisibleSelectionChangeIfNecessary();
 
-    LocalFrame* m_frame;
+    VisibleSelection validateSelection(const VisibleSelection&);
+
+    RawPtrWillBeMember<LocalFrame> m_frame;
 
     LayoutUnit m_xPosForVerticalArrowNavigation;
 
@@ -258,17 +279,17 @@ private:
     // 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;
+    RefPtrWillBeMember<Range> m_logicalRange;
 
-    RefPtr<Node> m_previousCaretNode; // The last node which painted the caret. Retained for clearing the old caret when it moves.
+    RefPtrWillBeMember<Node> m_previousCaretNode; // The last node which painted the caret. Retained for clearing the old caret when it moves.
+    LayoutRect m_previousCaretRect;
 
-    RefPtr<EditingStyle> m_typingStyle;
+    RefPtrWillBeMember<EditingStyle> m_typingStyle;
 
     Timer<FrameSelection> m_caretBlinkTimer;
-    // The painted bounds of the caret in absolute coordinates
-    IntRect m_absCaretBounds;
-    bool m_absCaretBoundsDirty : 1;
-    bool m_caretPaint : 1;
+
+    bool m_caretRectDirty : 1;
+    bool m_shouldPaintCaret : 1;
     bool m_isCaretBlinkingSuspended : 1;
     bool m_focused : 1;
     bool m_shouldShowBlockCursor : 1;
@@ -284,16 +305,16 @@ inline void FrameSelection::clearTypingStyle()
     m_typingStyle.clear();
 }
 
-inline void FrameSelection::setTypingStyle(PassRefPtr<EditingStyle> style)
+inline void FrameSelection::setTypingStyle(PassRefPtrWillBeRawPtr<EditingStyle> style)
 {
     m_typingStyle = style;
 }
-} // namespace WebCore
+} // namespace blink
 
 #ifndef NDEBUG
 // Outside the WebCore namespace for ease of invocation from gdb.
-void showTree(const WebCore::FrameSelection&);
-void showTree(const WebCore::FrameSelection*);
+void showTree(const blink::FrameSelection&);
+void showTree(const blink::FrameSelection*);
 #endif
 
 #endif // FrameSelection_h