summaryrefslogtreecommitdiff
path: root/Source/WebCore/page/DOMSelection.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/page/DOMSelection.h')
-rw-r--r--Source/WebCore/page/DOMSelection.h135
1 files changed, 59 insertions, 76 deletions
diff --git a/Source/WebCore/page/DOMSelection.h b/Source/WebCore/page/DOMSelection.h
index 1dda6abea..65836a9c8 100644
--- a/Source/WebCore/page/DOMSelection.h
+++ b/Source/WebCore/page/DOMSelection.h
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2007 Apple Inc. All rights reserved.
- * Copyright (C) 2012 Google Inc. All rights reserved.
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2012 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -11,7 +11,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
@@ -27,85 +27,68 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
-#ifndef DOMSelection_h
-#define DOMSelection_h
+#pragma once
#include "DOMWindowProperty.h"
+#include "ExceptionOr.h"
#include <wtf/Forward.h>
-#include <wtf/PassRefPtr.h>
#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
namespace WebCore {
- class Frame;
- class Node;
- class Position;
- class Range;
- class TreeScope;
- class VisibleSelection;
-
- typedef int ExceptionCode;
-
- class DOMSelection : public RefCounted<DOMSelection>, public DOMWindowProperty {
- public:
- static PassRefPtr<DOMSelection> create(const TreeScope* treeScope) { return adoptRef(new DOMSelection(treeScope)); }
-
- void clearTreeScope();
-
- // Safari Selection Object API
- // These methods return the valid equivalents of internal editing positions.
- Node* baseNode() const;
- Node* extentNode() const;
- int baseOffset() const;
- int extentOffset() const;
- String type() const;
- void setBaseAndExtent(Node* baseNode, int baseOffset, Node* extentNode, int extentOffset, ExceptionCode&);
- void setPosition(Node*, int offset, ExceptionCode&);
- void modify(const String& alter, const String& direction, const String& granularity);
-
- // Mozilla Selection Object API
- // In Firefox, anchor/focus are the equal to the start/end of the selection,
- // but reflect the direction in which the selection was made by the user. That does
- // not mean that they are base/extent, since the base/extent don't reflect
- // expansion.
- // These methods return the valid equivalents of internal editing positions.
- Node* anchorNode() const;
- int anchorOffset() const;
- Node* focusNode() const;
- int focusOffset() const;
- bool isCollapsed() const;
- int rangeCount() const;
- void collapse(Node*, int offset, ExceptionCode&);
- void collapseToEnd(ExceptionCode&);
- void collapseToStart(ExceptionCode&);
- void extend(Node*, int offset, ExceptionCode&);
- PassRefPtr<Range> getRangeAt(int, ExceptionCode&);
- void removeAllRanges();
- void addRange(Range*);
- void deleteFromDocument();
- bool containsNode(Node*, bool partlyContained) const;
- void selectAllChildren(Node*, ExceptionCode&);
-
- String toString();
-
- // Microsoft Selection Object API
- void empty();
-
- private:
- const TreeScope* m_treeScope;
-
- explicit DOMSelection(const TreeScope*);
-
- // Convenience method for accessors, does not NULL check m_frame.
- const VisibleSelection& visibleSelection() const;
-
- Node* shadowAdjustedNode(const Position&) const;
- int shadowAdjustedOffset(const Position&) const;
-
- bool isValidForPosition(Node*) const;
- };
+class Node;
+class Position;
+class Range;
+class VisibleSelection;
+
+class DOMSelection : public RefCounted<DOMSelection>, public DOMWindowProperty {
+public:
+ static Ref<DOMSelection> create(Frame& frame) { return adoptRef(*new DOMSelection(frame)); }
+
+ Node* baseNode() const;
+ Node* extentNode() const;
+ unsigned baseOffset() const;
+ unsigned extentOffset() const;
+ String type() const;
+ void setBaseAndExtent(Node* baseNode, unsigned baseOffset, Node* extentNode, unsigned extentOffset);
+ void setPosition(Node*, unsigned offset);
+ void modify(const String& alter, const String& direction, const String& granularity);
+
+ // The anchor and focus are the start and end of the selection, and
+ // reflect the direction in which the selection was made by the user.
+ // The base and extent are different, because they don't reflect expansion.
+ Node* anchorNode() const;
+ unsigned anchorOffset() const;
+ Node* focusNode() const;
+ unsigned focusOffset() const;
+ bool isCollapsed() const;
+ unsigned rangeCount() const;
+ void collapse(Node*, unsigned offset);
+ ExceptionOr<void> collapseToEnd();
+ ExceptionOr<void> collapseToStart();
+ ExceptionOr<void> extend(Node&, unsigned offset);
+ ExceptionOr<Ref<Range>> getRangeAt(unsigned);
+ void removeAllRanges();
+ void addRange(Range&);
+ void deleteFromDocument();
+ bool containsNode(Node&, bool partlyContained) const;
+ void selectAllChildren(Node&);
+
+ String toString();
+
+ void empty();
+
+private:
+ explicit DOMSelection(Frame&);
+
+ // Convenience method for accessors, caller must null-check m_frame.
+ const VisibleSelection& visibleSelection() const;
+
+ Node* shadowAdjustedNode(const Position&) const;
+ unsigned shadowAdjustedOffset(const Position&) const;
+
+ bool isValidForPosition(Node*) const;
+};
} // namespace WebCore
-
-#endif // DOMSelection_h