2011-02-04 Daniel Cheng <dcheng@chromium.org>
[WebKit.git] / Source / WebKit / chromium / src / PlatformBridge.cpp
index 041d4a0c4356ecbe47cda93db299ebff0bc279bd..b09d1506740fad9d25d32024102da05bd5da0d9e 100644 (file)
@@ -132,6 +132,14 @@ static WebWidgetClient* toWebWidgetClient(Widget* widget)
     return chromeClientImpl->webView()->client();
 }
 
+static WebClipboard* getClipboard(const Frame* frame)
+{
+    WebFrameImpl* frameImpl = WebFrameImpl::fromFrame(frame);
+    if (!frameImpl || !frameImpl->client())
+        return 0;
+    return frameImpl->client()->clipboard();
+}
+
 static WebCookieJar* getCookieJar(const Document* document)
 {
     WebFrameImpl* frameImpl = WebFrameImpl::fromFrame(document->frame());
@@ -217,9 +225,15 @@ void PlatformBridge::clipboardWriteData(const String& type,
 }
 
 HashSet<String> PlatformBridge::clipboardReadAvailableTypes(
-    PasteboardPrivate::ClipboardBuffer buffer, bool* containsFilenames)
+    const Frame* frame,
+    PasteboardPrivate::ClipboardBuffer buffer,
+    bool* containsFilenames)
 {
-    WebVector<WebString> result = webKitClient()->clipboard()->readAvailableTypes(
+    WebClipboard* clipboard = getClipboard(frame);
+    if (!clipboard)
+        return HashSet<String>();
+
+    WebVector<WebString> result = clipboard->readAvailableTypes(
         static_cast<WebClipboard::Buffer>(buffer), containsFilenames);
     HashSet<String> types;
     for (size_t i = 0; i < result.size(); ++i)
@@ -227,12 +241,19 @@ HashSet<String> PlatformBridge::clipboardReadAvailableTypes(
     return types;
 }
 
-bool PlatformBridge::clipboardReadData(PasteboardPrivate::ClipboardBuffer buffer,
-                                       const String& type, String& data, String& metadata)
+bool PlatformBridge::clipboardReadData(const Frame* frame,
+                                       PasteboardPrivate::ClipboardBuffer buffer,
+                                       const String& type,
+                                       String& data,
+                                       String& metadata)
 {
+    WebClipboard* clipboard = getClipboard(frame);
+    if (!clipboard)
+        return false;
+
     WebString resultData;
     WebString resultMetadata;
-    bool succeeded = webKitClient()->clipboard()->readData(
+    bool succeeded = clipboard->readData(
         static_cast<WebClipboard::Buffer>(buffer), type, &resultData, &resultMetadata);
     if (succeeded) {
         data = resultData;
@@ -241,9 +262,14 @@ bool PlatformBridge::clipboardReadData(PasteboardPrivate::ClipboardBuffer buffer
     return succeeded;
 }
 
-Vector<String> PlatformBridge::clipboardReadFilenames(PasteboardPrivate::ClipboardBuffer buffer)
+Vector<String> PlatformBridge::clipboardReadFilenames(const Frame* frame,
+                                                      PasteboardPrivate::ClipboardBuffer buffer)
 {
-    WebVector<WebString> result = webKitClient()->clipboard()->readFilenames(
+    WebClipboard* clipboard = getClipboard(frame);
+    if (!clipboard)
+        return Vector<String>();
+
+    WebVector<WebString> result = clipboard->readFilenames(
         static_cast<WebClipboard::Buffer>(buffer));
     Vector<String> convertedResult;
     for (size_t i = 0; i < result.size(); ++i)
@@ -509,12 +535,6 @@ PassRefPtr<IDBFactoryBackendInterface> PlatformBridge::idbFactory()
     return IDBFactoryBackendProxy::create();
 }
 
-void PlatformBridge::idbShutdown()
-{
-    // In the browser process, this shuts down the utility process. In the renderer process, it does nothing.
-    webKitClient()->idbShutdown();
-}
-
 void PlatformBridge::createIDBKeysFromSerializedValuesAndKeyPath(const Vector<RefPtr<SerializedScriptValue> >& values, const String& keyPath, Vector<RefPtr<IDBKey> >& keys)
 {
     WebVector<WebSerializedScriptValue> webValues = values;
@@ -791,6 +811,15 @@ static WebThemeEngine::Part WebThemePart(PlatformBridge::ThemePart part)
     case PlatformBridge::PartScrollbarVerticalThumb: return WebThemeEngine::PartScrollbarVerticalThumb;
     case PlatformBridge::PartScrollbarHorizontalTrack: return WebThemeEngine::PartScrollbarHorizontalTrack;
     case PlatformBridge::PartScrollbarVerticalTrack: return WebThemeEngine::PartScrollbarVerticalTrack;
+    case PlatformBridge::PartCheckbox: return WebThemeEngine::PartCheckbox;
+    case PlatformBridge::PartRadio: return WebThemeEngine::PartRadio;
+    case PlatformBridge::PartButton: return WebThemeEngine::PartButton;
+    case PlatformBridge::PartTextField: return WebThemeEngine::PartTextField;
+    case PlatformBridge::PartMenuList: return WebThemeEngine::PartMenuList;
+    case PlatformBridge::PartSliderTrack: return WebThemeEngine::PartSliderTrack;
+    case PlatformBridge::PartSliderThumb: return WebThemeEngine::PartSliderThumb;
+    case PlatformBridge::PartInnerSpinButton: return WebThemeEngine::PartInnerSpinButton;
+    case PlatformBridge::PartProgressBar: return WebThemeEngine::PartProgressBar;
     }
     ASSERT_NOT_REACHED();
     return WebThemeEngine::PartScrollbarDownArrow;
@@ -810,11 +839,53 @@ static WebThemeEngine::State WebThemeState(PlatformBridge::ThemePaintState state
 
 static void GetWebThemeExtraParams(PlatformBridge::ThemePart part, PlatformBridge::ThemePaintState state, const PlatformBridge::ThemePaintExtraParams* extraParams, WebThemeEngine::ExtraParams* webThemeExtraParams)
 {
-    if (part == PlatformBridge::PartScrollbarHorizontalTrack || part == PlatformBridge::PartScrollbarVerticalTrack) {
+    switch (part) {
+    case PlatformBridge::PartScrollbarHorizontalTrack:
+    case PlatformBridge::PartScrollbarVerticalTrack:
         webThemeExtraParams->scrollbarTrack.trackX = extraParams->scrollbarTrack.trackX;
         webThemeExtraParams->scrollbarTrack.trackY = extraParams->scrollbarTrack.trackY;
         webThemeExtraParams->scrollbarTrack.trackWidth = extraParams->scrollbarTrack.trackWidth;
         webThemeExtraParams->scrollbarTrack.trackHeight = extraParams->scrollbarTrack.trackHeight;
+        break;
+    case PlatformBridge::PartCheckbox:
+        webThemeExtraParams->button.checked = extraParams->button.checked;
+        webThemeExtraParams->button.indeterminate = extraParams->button.indeterminate;
+        break;
+    case PlatformBridge::PartRadio:
+        webThemeExtraParams->button.checked = extraParams->button.checked;
+        break;
+    case PlatformBridge::PartButton:
+        webThemeExtraParams->button.isDefault = extraParams->button.isDefault;
+        webThemeExtraParams->button.backgroundColor = extraParams->button.backgroundColor;
+        break;
+    case PlatformBridge::PartTextField:
+        webThemeExtraParams->textField.isTextArea = extraParams->textField.isTextArea;
+        webThemeExtraParams->textField.isListbox = extraParams->textField.isListbox;
+        webThemeExtraParams->textField.backgroundColor = extraParams->textField.backgroundColor;
+        break;
+    case PlatformBridge::PartMenuList:
+        webThemeExtraParams->menuList.arrowX = extraParams->menuList.arrowX;
+        webThemeExtraParams->menuList.arrowY = extraParams->menuList.arrowY;
+        webThemeExtraParams->menuList.backgroundColor = extraParams->menuList.backgroundColor;
+        break;
+    case PlatformBridge::PartSliderTrack:
+    case PlatformBridge::PartSliderThumb:
+        webThemeExtraParams->slider.vertical = extraParams->slider.vertical;
+        webThemeExtraParams->slider.inDrag = extraParams->slider.inDrag;
+        break;
+    case PlatformBridge::PartInnerSpinButton:
+        webThemeExtraParams->innerSpin.spinUp = extraParams->innerSpin.spinUp;
+        webThemeExtraParams->innerSpin.readOnly = extraParams->innerSpin.readOnly;
+        break;
+    case PlatformBridge::PartProgressBar:
+        webThemeExtraParams->progressBar.determinate = extraParams->progressBar.determinate;
+        webThemeExtraParams->progressBar.valueRectX = extraParams->progressBar.valueRectX;
+        webThemeExtraParams->progressBar.valueRectY = extraParams->progressBar.valueRectY;
+        webThemeExtraParams->progressBar.valueRectWidth = extraParams->progressBar.valueRectWidth;
+        webThemeExtraParams->progressBar.valueRectHeight = extraParams->progressBar.valueRectHeight;
+        break;
+    default:
+        break; // Parts that have no extra params get here.
     }
 }