15267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)/*
25267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * Copyright (C) 2012 Google Inc. All rights reserved.
35267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *
45267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without
55267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * modification, are permitted provided that the following conditions
65267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * are met:
75267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * 1.  Redistributions of source code must retain the above copyright
85267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *     notice, this list of conditions and the following disclaimer.
95267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * 2.  Redistributions in binary form must reproduce the above copyright
105267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *     notice, this list of conditions and the following disclaimer in the
115267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *     documentation and/or other materials provided with the distribution.
125267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *
135267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
145267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
155267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
165267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
175267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
185267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
195267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
205267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
215267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
225267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
235267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) */
245267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
255267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#ifndef WebSurroundingText_h
265267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#define WebSurroundingText_h
275267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
285267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "../platform/WebPrivateOwnPtr.h"
295267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "../platform/WebString.h"
305267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "WebNode.h"
315267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "WebRange.h"
325267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
33c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
345267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
35e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)class SurroundingText;
365267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebHitTestResult;
375267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebNode;
385d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)class WebRange;
395267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)struct WebPoint;
405267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
415d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)// WebSurroundingText is a Blink API that gives access to the SurroundingText
425d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)// API. It allows caller to know the text surrounding a point or a range.
435267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebSurroundingText {
445267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)public:
455267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    WebSurroundingText() { }
465267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    ~WebSurroundingText() { reset(); }
475267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
4806f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    BLINK_EXPORT bool isNull() const;
4906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    BLINK_EXPORT void reset();
505267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
515d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // Initializes the object to get the surrounding text centered in the
525d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // position relative to a provided node.
535267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // The maximum length of the contents retrieved is defined by maxLength.
5406f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    BLINK_EXPORT void initialize(const WebNode&, const WebPoint&, size_t maxLength);
555267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
565d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // Initializes the object to get the text surrounding a given range.
575d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // The maximum length of the contents retrieved is defined by maxLength.
585d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // It does not include the text inside the range.
595d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    BLINK_EXPORT void initialize(const WebRange&, size_t maxLength);
605d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
615267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Surrounding text content retrieved.
6206f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    BLINK_EXPORT WebString textContent() const;
635267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
645d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // Offset in the text content of the initial hit position (or provided
655d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // offset in the node).
665d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // This should only be called when WebSurroundingText has been initialized
675d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // with a WebPoint.
685d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // DEPRECATED: use startOffsetInTextContent() or endOffsetInTextContent().
6906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    BLINK_EXPORT size_t hitOffsetInTextContent() const;
705267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
715d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // Start offset of the initial text in the text content.
725d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    BLINK_EXPORT size_t startOffsetInTextContent() const;
735d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
745d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // End offset of the initial text in the text content.
755d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    BLINK_EXPORT size_t endOffsetInTextContent() const;
765d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
775d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // Convert start/end positions in the content text string into a WebKit text
785d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    // range.
7906f816c7c76bc45a15e452ade8a34e8af077693eTorne (Richard Coles)    BLINK_EXPORT WebRange rangeFromContentOffsets(size_t startOffsetInContent, size_t endOffsetInContent);
805267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
815267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)protected:
82e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    WebPrivateOwnPtr<SurroundingText> m_private;
835267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)};
845267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
8551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} // namespace blink
865267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
875267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#endif
88