webengine/osswebengine/WebCore/page/DOMSelection.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2  * Copyright (C) 2007 Apple Inc.  All rights reserved.
       
     3  *
       
     4  * Redistribution and use in source and binary forms, with or without
       
     5  * modification, are permitted provided that the following conditions
       
     6  * are met:
       
     7  *
       
     8  * 1.  Redistributions of source code must retain the above copyright
       
     9  *     notice, this list of conditions and the following disclaimer. 
       
    10  * 2.  Redistributions in binary form must reproduce the above copyright
       
    11  *     notice, this list of conditions and the following disclaimer in the
       
    12  *     documentation and/or other materials provided with the distribution. 
       
    13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
       
    14  *     its contributors may be used to endorse or promote products derived
       
    15  *     from this software without specific prior written permission. 
       
    16  *
       
    17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
       
    18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
       
    20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
       
    21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
       
    22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
       
    23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
       
    24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
       
    26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    27  */
       
    28 
       
    29 
       
    30 #include "config.h"
       
    31 #include "DOMSelection.h"
       
    32 
       
    33 #include "Frame.h"
       
    34 #include "Node.h"
       
    35 #include "PlatformString.h"
       
    36 #include "Range.h"
       
    37 #include "SelectionController.h"
       
    38 
       
    39 namespace WebCore {
       
    40 
       
    41 DOMSelection::DOMSelection(Frame* frame)
       
    42     : m_frame(frame)
       
    43 {
       
    44 }
       
    45 
       
    46 Frame* DOMSelection::frame() const
       
    47 {
       
    48     return m_frame;
       
    49 }
       
    50 
       
    51 void DOMSelection::disconnectFrame()
       
    52 {
       
    53     m_frame = 0;
       
    54 }
       
    55 
       
    56 Node* DOMSelection::anchorNode() const
       
    57 {
       
    58     if (!m_frame)
       
    59         return 0;
       
    60     return m_frame->selectionController()->anchorNode();
       
    61 }
       
    62 
       
    63 Node* DOMSelection::baseNode() const
       
    64 {
       
    65     if (!m_frame)
       
    66         return 0;
       
    67     return m_frame->selectionController()->baseNode();
       
    68 }
       
    69 
       
    70 int DOMSelection::anchorOffset() const
       
    71 {
       
    72     if (!m_frame)
       
    73         return 0;
       
    74     return m_frame->selectionController()->anchorOffset();
       
    75 }
       
    76 
       
    77 int DOMSelection::baseOffset() const
       
    78 {
       
    79     if (!m_frame)
       
    80         return 0;
       
    81     return m_frame->selectionController()->baseOffset();
       
    82 }
       
    83 
       
    84 Node* DOMSelection::focusNode() const
       
    85 {
       
    86     if (!m_frame)
       
    87         return 0;
       
    88     return m_frame->selectionController()->focusNode();
       
    89 }
       
    90 
       
    91 Node* DOMSelection::extentNode() const
       
    92 {
       
    93     if (!m_frame)
       
    94         return 0;
       
    95     return m_frame->selectionController()->extentNode();
       
    96 }
       
    97 
       
    98 int DOMSelection::focusOffset() const
       
    99 {
       
   100     if (!m_frame)
       
   101         return 0;
       
   102     return m_frame->selectionController()->focusOffset();
       
   103 }
       
   104 
       
   105 int DOMSelection::extentOffset() const
       
   106 {
       
   107     if (!m_frame)
       
   108         return 0;
       
   109     return m_frame->selectionController()->extentOffset();
       
   110 }
       
   111 
       
   112 bool DOMSelection::isCollapsed() const
       
   113 {
       
   114     if (!m_frame)
       
   115         return false;
       
   116     return m_frame->selectionController()->isCollapsed();
       
   117 }
       
   118 
       
   119 String DOMSelection::type() const
       
   120 {
       
   121     if (!m_frame)
       
   122         return String();
       
   123     return m_frame->selectionController()->type();
       
   124 }
       
   125 
       
   126 int DOMSelection::rangeCount() const
       
   127 {
       
   128     if (!m_frame)
       
   129         return 0;
       
   130     return m_frame->selectionController()->rangeCount();
       
   131 }
       
   132 
       
   133 void DOMSelection::collapse(Node* node, int offset, ExceptionCode& ec)
       
   134 {
       
   135     if (!m_frame)
       
   136         return;
       
   137     m_frame->selectionController()->collapse(node, offset, ec);
       
   138 }
       
   139 
       
   140 void DOMSelection::collapseToEnd()
       
   141 {
       
   142     if (!m_frame)
       
   143         return;
       
   144     m_frame->selectionController()->collapseToEnd();
       
   145 }
       
   146 
       
   147 void DOMSelection::collapseToStart()
       
   148 {
       
   149     if (!m_frame)
       
   150         return;
       
   151     m_frame->selectionController()->collapseToStart();
       
   152 }
       
   153 
       
   154 void DOMSelection::empty()
       
   155 {
       
   156     if (!m_frame)
       
   157         return;
       
   158     m_frame->selectionController()->empty();
       
   159 }
       
   160 
       
   161 void DOMSelection::setBaseAndExtent(Node* baseNode, int baseOffset, Node* extentNode, int extentOffset, ExceptionCode& ec)
       
   162 {
       
   163     if (!m_frame)
       
   164         return;
       
   165     m_frame->selectionController()->setBaseAndExtent(baseNode, baseOffset, extentNode, extentOffset, ec);
       
   166 }
       
   167 
       
   168 void DOMSelection::setPosition(Node* node, int offset, ExceptionCode& ec)
       
   169 {
       
   170     if (!m_frame)
       
   171         return;
       
   172     m_frame->selectionController()->setPosition(node, offset, ec);
       
   173 }
       
   174 
       
   175 void DOMSelection::setPosition(Node* node, ExceptionCode& ec)
       
   176 {
       
   177     if (!m_frame)
       
   178         return;
       
   179     m_frame->selectionController()->setPosition(node, 0, ec);
       
   180 }
       
   181 
       
   182 void DOMSelection::modify(const String& alter, const String& direction, const String& granularity)
       
   183 {
       
   184     if (!m_frame)
       
   185         return;
       
   186     m_frame->selectionController()->modify(alter, direction, granularity);
       
   187 }
       
   188 
       
   189 PassRefPtr<Range> DOMSelection::getRangeAt(int index, ExceptionCode& ec)
       
   190 {
       
   191     if (!m_frame)
       
   192         return 0;
       
   193     return m_frame->selectionController()->getRangeAt(index, ec);
       
   194 }
       
   195 
       
   196 void DOMSelection::removeAllRanges()
       
   197 {
       
   198     if (!m_frame)
       
   199         return;
       
   200     m_frame->selectionController()->removeAllRanges();
       
   201 }
       
   202 
       
   203 void DOMSelection::addRange(Range* range)
       
   204 {
       
   205     if (!m_frame)
       
   206         return;
       
   207     m_frame->selectionController()->addRange(range);
       
   208 }
       
   209 
       
   210 String DOMSelection::toString()
       
   211 {
       
   212     if (!m_frame)
       
   213         return String();
       
   214     return m_frame->selectionController()->toString();
       
   215 }
       
   216 
       
   217 } // namespace WebCore