summaryrefslogtreecommitdiffstats
path: root/webkit/glue
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-14 16:32:59 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-14 16:32:59 +0000
commit88efb7ec99239eeecaa17d21f8635be1bce29cca (patch)
treeb1a988fbca10748e584f78abb755036e63ff335f /webkit/glue
parentc9d6a1df8ef5fd2c3f134dcb544663ce8bd21c7b (diff)
downloadchromium_src-88efb7ec99239eeecaa17d21f8635be1bce29cca.zip
chromium_src-88efb7ec99239eeecaa17d21f8635be1bce29cca.tar.gz
chromium_src-88efb7ec99239eeecaa17d21f8635be1bce29cca.tar.bz2
Replace ShowAsPopupWithItems to CreatePopupWidgetWithInfo. Also,
make use of WebPopupMenuInfo from the WebKit API. WebMenuItem remains in webkit/glue for convenience with IPC marshalling and related usage in Chrome. This work is precursor to switching over to using WebWidget from the WebKit API. BUG=16234 TEST=html select drop downs should still work on the mac. try switching languages on news.google.com. R=paul Review URL: http://codereview.chromium.org/155378 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20624 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r--webkit/glue/chrome_client_impl.cc101
-rw-r--r--webkit/glue/chrome_client_impl.h9
-rw-r--r--webkit/glue/webmenuitem.h33
-rw-r--r--webkit/glue/webmenurunner_mac.h2
-rw-r--r--webkit/glue/webmenurunner_mac.mm2
-rw-r--r--webkit/glue/webview_delegate.h9
-rw-r--r--webkit/glue/webwidget_delegate.h31
-rw-r--r--webkit/glue/webwidget_impl.cc14
-rw-r--r--webkit/glue/webwidget_impl.h5
-rw-r--r--webkit/glue/webworker_impl.cc5
10 files changed, 99 insertions, 112 deletions
diff --git a/webkit/glue/chrome_client_impl.cc b/webkit/glue/chrome_client_impl.cc
index d868767..4c233f2 100644
--- a/webkit/glue/chrome_client_impl.cc
+++ b/webkit/glue/chrome_client_impl.cc
@@ -39,6 +39,7 @@ MSVC_POP_WARNING();
#include "webkit/api/public/WebCursorInfo.h"
#include "webkit/api/public/WebInputEvent.h"
#include "webkit/api/public/WebKit.h"
+#include "webkit/api/public/WebPopupMenuInfo.h"
#include "webkit/api/public/WebRect.h"
#include "webkit/api/public/WebURLRequest.h"
#include "webkit/api/src/WrappedResourceRequest.h"
@@ -49,11 +50,16 @@ MSVC_POP_WARNING();
#include "webkit/glue/webview_impl.h"
#include "webkit/glue/webwidget_impl.h"
+using WebCore::PopupContainer;
+using WebCore::PopupItem;
+
using WebKit::WebCursorInfo;
using WebKit::WebInputEvent;
using WebKit::WebMouseEvent;
+using WebKit::WebPopupMenuInfo;
using WebKit::WebRect;
using WebKit::WebURLRequest;
+using WebKit::WebVector;
using WebKit::WrappedResourceRequest;
// Callback class that's given to the WebViewDelegate during a file choose
@@ -544,65 +550,25 @@ void ChromeClientImpl::runOpenPanel(WebCore::Frame* frame,
delegate->RunFileChooser(multiple_files, string16(), suggestion, chooser);
}
-void ChromeClientImpl::popupOpened(WebCore::PopupContainer* popup_container,
+void ChromeClientImpl::popupOpened(PopupContainer* popup_container,
const WebCore::IntRect& bounds,
bool activatable,
- bool handle_external) {
- if (handle_external) {
- // We're going to handle the popup with native controls by the external
- // embedder.
- popupOpenedInternal(popup_container, bounds, activatable);
- return;
- }
-
- WebViewDelegate* delegate = webview_->delegate();
- if (delegate) {
- WebWidgetImpl* webwidget =
- static_cast<WebWidgetImpl*>(delegate->CreatePopupWidget(webview_,
- activatable));
- webwidget->Init(popup_container, webkit_glue::IntRectToWebRect(bounds));
- }
-}
-
-void ChromeClientImpl::popupOpenedInternal(
- WebCore::PopupContainer* popup_container,
- const WebCore::IntRect& bounds,
- bool activatable) {
+ bool handle_externally) {
WebViewDelegate* delegate = webview_->delegate();
if (!delegate)
return;
- WebWidgetImpl* webwidget =
- static_cast<WebWidgetImpl*>(delegate->CreatePopupWidget(webview_,
- activatable));
- // Convert WebKit types for Chromium.
- std::vector<WebMenuItem> popup_items;
- const WTF::Vector<WebCore::PopupItem*>& items = popup_container->popupData();
- for (int i = 0; i < static_cast<int>(items.size()); ++i) {
- WebMenuItem menu_item;
- menu_item.label = webkit_glue::StringToString16(items[i]->label);
- menu_item.enabled = items[i]->enabled;
- switch (items[i]->type) {
- case WebCore::PopupItem::TypeOption:
- menu_item.type = WebMenuItem::OPTION;
- break;
- case WebCore::PopupItem::TypeGroup:
- menu_item.type = WebMenuItem::GROUP;
- break;
- case WebCore::PopupItem::TypeSeparator:
- menu_item.type = WebMenuItem::SEPARATOR;
- break;
- default:
- NOTIMPLEMENTED();
- }
- popup_items.push_back(menu_item);
+ WebWidget* webwidget;
+ if (handle_externally) {
+ WebPopupMenuInfo popup_info;
+ GetPopupMenuInfo(popup_container, &popup_info);
+ webwidget = delegate->CreatePopupWidgetWithInfo(webview_, popup_info);
+ } else {
+ webwidget = delegate->CreatePopupWidget(webview_, activatable);
}
- webwidget->InitWithItems(popup_container,
- webkit_glue::IntRectToWebRect(bounds),
- popup_container->menuItemHeight(),
- popup_container->selectedIndex(),
- popup_items);
+ static_cast<WebWidgetImpl*>(webwidget)->Init(
+ popup_container, webkit_glue::IntRectToWebRect(bounds));
}
void ChromeClientImpl::SetCursor(const WebCursorInfo& cursor) {
@@ -629,3 +595,36 @@ void ChromeClientImpl::formStateDidChange(const WebCore::Node*) {
if (delegate)
delegate->OnNavStateChanged(webview_);
}
+
+void ChromeClientImpl::GetPopupMenuInfo(PopupContainer* popup_container,
+ WebPopupMenuInfo* info) {
+ const Vector<PopupItem*>& input_items = popup_container->popupData();
+
+ WebVector<WebPopupMenuInfo::Item> output_items(input_items.size());
+
+ for (size_t i = 0; i < input_items.size(); ++i) {
+ const PopupItem& input_item = *input_items[i];
+ WebPopupMenuInfo::Item& output_item = output_items[i];
+
+ output_item.label = webkit_glue::StringToWebString(input_item.label);
+ output_item.enabled = input_item.enabled;
+
+ switch (input_item.type) {
+ case PopupItem::TypeOption:
+ output_item.type = WebPopupMenuInfo::Item::Option;
+ break;
+ case PopupItem::TypeGroup:
+ output_item.type = WebPopupMenuInfo::Item::Group;
+ break;
+ case PopupItem::TypeSeparator:
+ output_item.type = WebPopupMenuInfo::Item::Separator;
+ break;
+ default:
+ NOTREACHED();
+ }
+ }
+
+ info->itemHeight = popup_container->menuItemHeight();
+ info->selectedIndex = popup_container->selectedIndex();
+ info->items.swap(output_items);
+}
diff --git a/webkit/glue/chrome_client_impl.h b/webkit/glue/chrome_client_impl.h
index cebffc2..2a91659 100644
--- a/webkit/glue/chrome_client_impl.h
+++ b/webkit/glue/chrome_client_impl.h
@@ -22,6 +22,7 @@ struct WindowFeatures;
namespace WebKit {
struct WebCursorInfo;
+struct WebPopupMenuInfo;
}
// Handles window-level notifications from WebCore on behalf of a WebView.
@@ -131,10 +132,7 @@ class ChromeClientImpl : public WebCore::ChromeClientChromium {
virtual void popupOpened(WebCore::PopupContainer* popup_container,
const WebCore::IntRect& bounds,
bool activatable,
- bool handle_external);
- void popupOpenedInternal(WebCore::PopupContainer* popup_container,
- const WebCore::IntRect& bounds,
- bool activatable);
+ bool handle_externally);
void SetCursor(const WebKit::WebCursorInfo& cursor);
void SetCursorForPlugin(const WebKit::WebCursorInfo& cursor);
@@ -144,6 +142,9 @@ class ChromeClientImpl : public WebCore::ChromeClientChromium {
virtual PassOwnPtr<WebCore::HTMLParserQuirks> createHTMLParserQuirks() { return 0; }
private:
+ void GetPopupMenuInfo(WebCore::PopupContainer* popup_container,
+ WebKit::WebPopupMenuInfo* info);
+
WebViewImpl* webview_; // weak pointer
bool toolbars_visible_;
bool statusbar_visible_;
diff --git a/webkit/glue/webmenuitem.h b/webkit/glue/webmenuitem.h
new file mode 100644
index 0000000..584e071
--- /dev/null
+++ b/webkit/glue/webmenuitem.h
@@ -0,0 +1,33 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBMENUITEM_H_
+#define WEBMENUITEM_H_
+
+#include "base/string16.h"
+#include "webkit/api/public/WebPopupMenuInfo.h"
+
+// Container for information about entries in an HTML select popup menu.
+struct WebMenuItem {
+ enum Type {
+ OPTION = WebKit::WebPopupMenuInfo::Item::Option,
+ GROUP = WebKit::WebPopupMenuInfo::Item::Group,
+ SEPARATOR = WebKit::WebPopupMenuInfo::Item::Separator
+ };
+
+ string16 label;
+ Type type;
+ bool enabled;
+
+ WebMenuItem() : type(OPTION), enabled(false) {
+ }
+
+ WebMenuItem(const WebKit::WebPopupMenuInfo::Item& item)
+ : label(item.label),
+ type(static_cast<Type>(item.type)),
+ enabled(item.enabled) {
+ }
+};
+
+#endif // WEBMENUITEM_H_
diff --git a/webkit/glue/webmenurunner_mac.h b/webkit/glue/webmenurunner_mac.h
index 8d822a4..b83abeb 100644
--- a/webkit/glue/webmenurunner_mac.h
+++ b/webkit/glue/webmenurunner_mac.h
@@ -10,7 +10,7 @@
#include <vector>
#include "base/scoped_nsobject.h"
-#include "webkit/glue/webwidget_delegate.h"
+#include "webkit/glue/webmenuitem.h"
// WebMenuRunner ---------------------------------------------------------------
diff --git a/webkit/glue/webmenurunner_mac.mm b/webkit/glue/webmenurunner_mac.mm
index 8997f05..99c52bd 100644
--- a/webkit/glue/webmenurunner_mac.mm
+++ b/webkit/glue/webmenurunner_mac.mm
@@ -25,7 +25,7 @@
menu_.reset([[NSMenu alloc] initWithTitle:@""]);
[menu_ setAutoenablesItems:NO];
index_ = -1;
- for (int i = 0; i < static_cast<int>(items.size()); ++i)
+ for (size_t i = 0; i < items.size(); ++i)
[self addItem:items[i]];
}
return self;
diff --git a/webkit/glue/webview_delegate.h b/webkit/glue/webview_delegate.h
index 6106d1d..eafd383 100644
--- a/webkit/glue/webview_delegate.h
+++ b/webkit/glue/webview_delegate.h
@@ -52,6 +52,7 @@ class WebMediaPlayerClient;
class WebURLRequest;
class WebURLResponse;
struct WebPoint;
+struct WebPopupMenuInfo;
struct WebRect;
struct WebURLError;
}
@@ -119,6 +120,14 @@ class WebViewDelegate : virtual public WebWidgetDelegate {
return NULL;
}
+ // Like CreatePopupWidget, except the actual widget is rendered by the
+ // embedder using the supplied info.
+ virtual WebWidget* CreatePopupWidgetWithInfo(
+ WebView* webview,
+ const WebKit::WebPopupMenuInfo& info) {
+ return NULL;
+ }
+
// This method is called to create a WebPluginDelegate implementation when a
// new plugin is instanced. See webkit_glue::CreateWebPluginDelegateHelper
// for a default WebPluginDelegate implementation.
diff --git a/webkit/glue/webwidget_delegate.h b/webkit/glue/webwidget_delegate.h
index 17704b0d..a891cb1 100644
--- a/webkit/glue/webwidget_delegate.h
+++ b/webkit/glue/webwidget_delegate.h
@@ -19,22 +19,6 @@ struct WebScreenInfo;
class WebWidget;
struct WebPluginGeometry;
-struct WebMenuItem {
- // Container for information about entries in an HTML select popup menu.
- // Types must be kept in sync with PopupListBox::ListItemType in
- // WebCore/platform/chromium/PopupMenuChromium.h. This won't change often
- // (if ever).
- enum Type {
- OPTION = 0,
- GROUP,
- SEPARATOR
- };
-
- string16 label;
- Type type;
- bool enabled;
-};
-
class WebWidgetDelegate {
public:
// Called when a region of the WebWidget needs to be re-painted.
@@ -54,21 +38,6 @@ class WebWidgetDelegate {
virtual void Show(WebWidget* webwidget,
WindowOpenDisposition disposition) = 0;
- // Used for displaying HTML popup menus on Mac OS X (other platforms will use
- // Show() above). |bounds| represents the positioning on the screen (in WebKit
- // coordinates, origin at the top left corner) of the button that will display
- // the menu. It will be used, along with |item_height| (which refers to the
- // size of each entry in the menu), to position the menu on the screen.
- // |selected_index| indicates the menu item that should be drawn as selected
- // when the menu initially is displayed. |items| contains information about
- // each of the entries in the popup menu, such as the type (separator, option,
- // group), the text representation and the item's enabled status.
- virtual void ShowAsPopupWithItems(WebWidget* webwidget,
- const WebKit::WebRect& bounds,
- int item_height,
- int selected_index,
- const std::vector<WebMenuItem>& items) = 0;
-
// This method is called to instruct the window containing the WebWidget to
// close. Note: This method should just be the trigger that causes the
// WebWidget to eventually close. It should not actually be destroyed until
diff --git a/webkit/glue/webwidget_impl.cc b/webkit/glue/webwidget_impl.cc
index cb3a0c9..618a9bf 100644
--- a/webkit/glue/webwidget_impl.cc
+++ b/webkit/glue/webwidget_impl.cc
@@ -70,20 +70,6 @@ void WebWidgetImpl::Init(WebCore::FramelessScrollView* widget,
}
}
-void WebWidgetImpl::InitWithItems(WebCore::FramelessScrollView* widget,
- const WebRect& bounds,
- int item_height,
- int selected_index,
- const std::vector<WebMenuItem>& items) {
- widget_ = widget;
- widget_->setClient(this);
-
- if (delegate_) {
- delegate_->ShowAsPopupWithItems(this, bounds, item_height,
- selected_index, items);
- }
-}
-
void WebWidgetImpl::MouseMove(const WebMouseEvent& event) {
// don't send mouse move messages if the mouse hasn't moved.
if (event.x != last_mouse_position_.x ||
diff --git a/webkit/glue/webwidget_impl.h b/webkit/glue/webwidget_impl.h
index a0078db..a1a1b18 100644
--- a/webkit/glue/webwidget_impl.h
+++ b/webkit/glue/webwidget_impl.h
@@ -59,11 +59,6 @@ class WebWidgetImpl : public WebWidget,
// WebWidgetImpl
void Init(WebCore::FramelessScrollView* widget,
const WebKit::WebRect& bounds);
- void InitWithItems(WebCore::FramelessScrollView* widget,
- const WebKit::WebRect& bounds,
- int item_height,
- int selected_index,
- const std::vector<WebMenuItem>& items);
const WebKit::WebSize& size() const { return size_; }
diff --git a/webkit/glue/webworker_impl.cc b/webkit/glue/webworker_impl.cc
index 4016e85..c706524 100644
--- a/webkit/glue/webworker_impl.cc
+++ b/webkit/glue/webworker_impl.cc
@@ -69,11 +69,6 @@ class WorkerWebViewDelegate : public WebViewDelegate {
virtual void SetWindowRect(WebWidget *webwidget,
const WebKit::WebRect &rect) { }
virtual void Show(WebWidget *webwidget, WindowOpenDisposition disposition) { }
- virtual void ShowAsPopupWithItems(WebWidget *webwidget,
- const WebKit::WebRect &bounds,
- int item_height,
- int selected_index,
- const std::vector<WebMenuItem> &items) { }
// Tell the loader to load the data into the 'shadow page' synchronously,
// so we can grab the resulting Document right after load.
virtual void DidCreateDataSource(WebFrame* frame, WebKit::WebDataSource* ds) {