Home | History | Annotate | Download | only in InjectedBundle
      1 /*
      2  * Copyright (C) 2010 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  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
     14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
     17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     23  * THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #include "config.h"
     27 #include "InjectedBundlePageEditorClient.h"
     28 
     29 #include "InjectedBundleNodeHandle.h"
     30 #include "InjectedBundleRangeHandle.h"
     31 #include "WKAPICast.h"
     32 #include "WKBundleAPICast.h"
     33 #include <wtf/text/WTFString.h>
     34 
     35 using namespace WebCore;
     36 
     37 namespace WebKit {
     38 
     39 bool InjectedBundlePageEditorClient::shouldBeginEditing(WebPage* page, Range* range)
     40 {
     41     if (m_client.shouldBeginEditing) {
     42         RefPtr<InjectedBundleRangeHandle> rangeHandle = InjectedBundleRangeHandle::getOrCreate(range);
     43         return m_client.shouldBeginEditing(toAPI(page), toAPI(rangeHandle.get()), m_client.clientInfo);
     44     }
     45     return true;
     46 }
     47 
     48 bool InjectedBundlePageEditorClient::shouldEndEditing(WebPage* page, Range* range)
     49 {
     50     if (m_client.shouldEndEditing) {
     51         RefPtr<InjectedBundleRangeHandle> rangeHandle = InjectedBundleRangeHandle::getOrCreate(range);
     52         return m_client.shouldEndEditing(toAPI(page), toAPI(rangeHandle.get()), m_client.clientInfo);
     53     }
     54     return true;
     55 }
     56 
     57 bool InjectedBundlePageEditorClient::shouldInsertNode(WebPage* page, Node* node, Range* rangeToReplace, EditorInsertAction action)
     58 {
     59     if (m_client.shouldInsertNode) {
     60         RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::getOrCreate(node);
     61         RefPtr<InjectedBundleRangeHandle> rangeToReplaceHandle = InjectedBundleRangeHandle::getOrCreate(rangeToReplace);
     62         return m_client.shouldInsertNode(toAPI(page), toAPI(nodeHandle.get()), toAPI(rangeToReplaceHandle.get()), toAPI(action), m_client.clientInfo);
     63     }
     64     return true;
     65 }
     66 
     67 bool InjectedBundlePageEditorClient::shouldInsertText(WebPage* page, StringImpl* text, Range* rangeToReplace, EditorInsertAction action)
     68 {
     69     if (m_client.shouldInsertText) {
     70         RefPtr<InjectedBundleRangeHandle> rangeToReplaceHandle = InjectedBundleRangeHandle::getOrCreate(rangeToReplace);
     71         return m_client.shouldInsertText(toAPI(page), toAPI(text), toAPI(rangeToReplaceHandle.get()), toAPI(action), m_client.clientInfo);
     72     }
     73     return true;
     74 }
     75 
     76 bool InjectedBundlePageEditorClient::shouldDeleteRange(WebPage* page, Range* range)
     77 {
     78     if (m_client.shouldDeleteRange) {
     79         RefPtr<InjectedBundleRangeHandle> rangeHandle = InjectedBundleRangeHandle::getOrCreate(range);
     80         return m_client.shouldDeleteRange(toAPI(page), toAPI(rangeHandle.get()), m_client.clientInfo);
     81     }
     82     return true;
     83 }
     84 
     85 bool InjectedBundlePageEditorClient::shouldChangeSelectedRange(WebPage* page, Range* fromRange, Range* toRange, EAffinity affinity, bool stillSelecting)
     86 {
     87     if (m_client.shouldChangeSelectedRange) {
     88         RefPtr<InjectedBundleRangeHandle> fromRangeHandle = InjectedBundleRangeHandle::getOrCreate(fromRange);
     89         RefPtr<InjectedBundleRangeHandle> toRangeHandle = InjectedBundleRangeHandle::getOrCreate(toRange);
     90         return m_client.shouldChangeSelectedRange(toAPI(page), toAPI(fromRangeHandle.get()), toAPI(toRangeHandle.get()), toAPI(affinity), stillSelecting, m_client.clientInfo);
     91     }
     92     return true;
     93 }
     94 
     95 bool InjectedBundlePageEditorClient::shouldApplyStyle(WebPage* page, CSSStyleDeclaration* style, Range* range)
     96 {
     97     if (m_client.shouldApplyStyle) {
     98         RefPtr<InjectedBundleRangeHandle> rangeHandle = InjectedBundleRangeHandle::getOrCreate(range);
     99         return m_client.shouldApplyStyle(toAPI(page), toAPI(style), toAPI(rangeHandle.get()), m_client.clientInfo);
    100     }
    101     return true;
    102 }
    103 
    104 void InjectedBundlePageEditorClient::didBeginEditing(WebPage* page, StringImpl* notificationName)
    105 {
    106     if (m_client.didBeginEditing)
    107         m_client.didBeginEditing(toAPI(page), toAPI(notificationName), m_client.clientInfo);
    108 }
    109 
    110 void InjectedBundlePageEditorClient::didEndEditing(WebPage* page, StringImpl* notificationName)
    111 {
    112     if (m_client.didEndEditing)
    113         m_client.didEndEditing(toAPI(page), toAPI(notificationName), m_client.clientInfo);
    114 }
    115 
    116 void InjectedBundlePageEditorClient::didChange(WebPage* page, StringImpl* notificationName)
    117 {
    118     if (m_client.didChange)
    119         m_client.didChange(toAPI(page), toAPI(notificationName), m_client.clientInfo);
    120 }
    121 
    122 void InjectedBundlePageEditorClient::didChangeSelection(WebPage* page, StringImpl* notificationName)
    123 {
    124     if (m_client.didChangeSelection)
    125         m_client.didChangeSelection(toAPI(page), toAPI(notificationName), m_client.clientInfo);
    126 }
    127 
    128 } // namespace WebKit
    129