Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: webkit/glue/webview_impl.cc

Issue 279001: Move autofill related WebView{Delegate} methods into the WebKit API.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/glue/webview_impl.h ('k') | webkit/tools/test_shell/test_webview_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2007-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2007-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "build/build_config.h" 6 #include "build/build_config.h"
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 MSVC_PUSH_WARNING_LEVEL(0); 9 MSVC_PUSH_WARNING_LEVEL(0);
10 #include "AXObjectCache.h" 10 #include "AXObjectCache.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 #include "base/keyboard_codes.h" 62 #include "base/keyboard_codes.h"
63 #include "base/logging.h" 63 #include "base/logging.h"
64 #include "base/message_loop.h" 64 #include "base/message_loop.h"
65 #include "webkit/api/public/WebAccessibilityObject.h" 65 #include "webkit/api/public/WebAccessibilityObject.h"
66 #include "webkit/api/public/WebDragData.h" 66 #include "webkit/api/public/WebDragData.h"
67 #include "webkit/api/public/WebInputEvent.h" 67 #include "webkit/api/public/WebInputEvent.h"
68 #include "webkit/api/public/WebMediaPlayerAction.h" 68 #include "webkit/api/public/WebMediaPlayerAction.h"
69 #include "webkit/api/public/WebPoint.h" 69 #include "webkit/api/public/WebPoint.h"
70 #include "webkit/api/public/WebRect.h" 70 #include "webkit/api/public/WebRect.h"
71 #include "webkit/api/public/WebString.h" 71 #include "webkit/api/public/WebString.h"
72 #include "webkit/api/public/WebVector.h"
72 #include "webkit/api/src/WebInputEventConversion.h" 73 #include "webkit/api/src/WebInputEventConversion.h"
73 #include "webkit/api/src/WebSettingsImpl.h" 74 #include "webkit/api/src/WebSettingsImpl.h"
74 #include "webkit/glue/dom_operations.h" 75 #include "webkit/glue/dom_operations.h"
75 #include "webkit/glue/glue_serialize.h" 76 #include "webkit/glue/glue_serialize.h"
76 #include "webkit/glue/glue_util.h" 77 #include "webkit/glue/glue_util.h"
77 #include "webkit/glue/image_resource_fetcher.h" 78 #include "webkit/glue/image_resource_fetcher.h"
78 #include "webkit/glue/searchable_form_data.h" 79 #include "webkit/glue/searchable_form_data.h"
79 #include "webkit/glue/webdevtoolsagent_impl.h" 80 #include "webkit/glue/webdevtoolsagent_impl.h"
80 #include "webkit/glue/webkit_glue.h" 81 #include "webkit/glue/webkit_glue.h"
81 #include "webkit/glue/webpopupmenu_impl.h" 82 #include "webkit/glue/webpopupmenu_impl.h"
(...skipping 22 matching lines...) Expand all
104 using WebKit::WebDragOperationNone; 105 using WebKit::WebDragOperationNone;
105 using WebKit::WebDragOperationsMask; 106 using WebKit::WebDragOperationsMask;
106 using WebKit::WebFrame; 107 using WebKit::WebFrame;
107 using WebKit::WebFrameClient; 108 using WebKit::WebFrameClient;
108 using WebKit::WebInputEvent; 109 using WebKit::WebInputEvent;
109 using WebKit::WebKeyboardEvent; 110 using WebKit::WebKeyboardEvent;
110 using WebKit::WebMediaPlayerAction; 111 using WebKit::WebMediaPlayerAction;
111 using WebKit::WebMouseEvent; 112 using WebKit::WebMouseEvent;
112 using WebKit::WebMouseWheelEvent; 113 using WebKit::WebMouseWheelEvent;
113 using WebKit::WebNavigationPolicy; 114 using WebKit::WebNavigationPolicy;
115 using WebKit::WebNode;
114 using WebKit::WebPoint; 116 using WebKit::WebPoint;
115 using WebKit::WebRect; 117 using WebKit::WebRect;
116 using WebKit::WebSettings; 118 using WebKit::WebSettings;
117 using WebKit::WebSettingsImpl; 119 using WebKit::WebSettingsImpl;
118 using WebKit::WebSize; 120 using WebKit::WebSize;
119 using WebKit::WebString; 121 using WebKit::WebString;
120 using WebKit::WebTextDirection; 122 using WebKit::WebTextDirection;
121 using WebKit::WebTextDirectionDefault; 123 using WebKit::WebTextDirectionDefault;
122 using WebKit::WebTextDirectionLeftToRight; 124 using WebKit::WebTextDirectionLeftToRight;
123 using WebKit::WebTextDirectionRightToLeft; 125 using WebKit::WebTextDirectionRightToLeft;
124 using WebKit::WebURL; 126 using WebKit::WebURL;
127 using WebKit::WebVector;
125 128
126 using webkit_glue::ImageResourceFetcher;
127 using webkit_glue::AccessibilityObjectToWebAccessibilityObject; 129 using webkit_glue::AccessibilityObjectToWebAccessibilityObject;
128 130
129 // Change the text zoom level by kTextSizeMultiplierRatio each time the user 131 // Change the text zoom level by kTextSizeMultiplierRatio each time the user
130 // zooms text in or out (ie., change by 20%). The min and max values limit 132 // zooms text in or out (ie., change by 20%). The min and max values limit
131 // text zoom to half and 3x the original text size. These three values match 133 // text zoom to half and 3x the original text size. These three values match
132 // those in Apple's port in WebKit/WebKit/WebView/WebView.mm 134 // those in Apple's port in WebKit/WebKit/WebView/WebView.mm
133 static const double kTextSizeMultiplierRatio = 1.2; 135 static const double kTextSizeMultiplierRatio = 1.2;
134 static const double kMinTextSizeMultiplier = 0.5; 136 static const double kMinTextSizeMultiplier = 0.5;
135 static const double kMaxTextSizeMultiplier = 3.0; 137 static const double kMaxTextSizeMultiplier = 3.0;
136 138
(...skipping 21 matching lines...) Expand all
158 160
159 // AutocompletePopupMenuClient 161 // AutocompletePopupMenuClient
160 class AutocompletePopupMenuClient : public WebCore::PopupMenuClient { 162 class AutocompletePopupMenuClient : public WebCore::PopupMenuClient {
161 public: 163 public:
162 AutocompletePopupMenuClient(WebViewImpl* webview) : text_field_(NULL), 164 AutocompletePopupMenuClient(WebViewImpl* webview) : text_field_(NULL),
163 selected_index_(0), 165 selected_index_(0),
164 webview_(webview) { 166 webview_(webview) {
165 } 167 }
166 168
167 void Init(WebCore::HTMLInputElement* text_field, 169 void Init(WebCore::HTMLInputElement* text_field,
168 const std::vector<std::wstring>& suggestions, 170 const WebVector<WebString>& suggestions,
169 int default_suggestion_index) { 171 int default_suggestion_index) {
170 DCHECK(default_suggestion_index < static_cast<int>(suggestions.size())); 172 DCHECK(default_suggestion_index < static_cast<int>(suggestions.size()));
171 text_field_ = text_field; 173 text_field_ = text_field;
172 selected_index_ = default_suggestion_index; 174 selected_index_ = default_suggestion_index;
173 SetSuggestions(suggestions); 175 SetSuggestions(suggestions);
174 176
175 FontDescription font_description; 177 FontDescription font_description;
176 webview_->theme()->systemFont(CSSValueWebkitControl, font_description); 178 webview_->theme()->systemFont(CSSValueWebkitControl, font_description);
177 // Use a smaller font size to match IE/Firefox. 179 // Use a smaller font size to match IE/Firefox.
178 // TODO(jcampan): http://crbug.com/7376 use the system size instead of a 180 // TODO(jcampan): http://crbug.com/7376 use the system size instead of a
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 ScrollbarClient* client, 279 ScrollbarClient* client,
278 ScrollbarOrientation orientation, 280 ScrollbarOrientation orientation,
279 ScrollbarControlSize size) { 281 ScrollbarControlSize size) {
280 RefPtr<Scrollbar> widget = Scrollbar::createNativeScrollbar(client, 282 RefPtr<Scrollbar> widget = Scrollbar::createNativeScrollbar(client,
281 orientation, 283 orientation,
282 size); 284 size);
283 return widget.release(); 285 return widget.release();
284 } 286 }
285 287
286 // AutocompletePopupMenuClient specific methods: 288 // AutocompletePopupMenuClient specific methods:
287 void SetSuggestions(const std::vector<std::wstring>& suggestions) { 289 void SetSuggestions(const WebVector<WebString>& suggestions) {
288 suggestions_.clear(); 290 suggestions_.clear();
289 for (std::vector<std::wstring>::const_iterator iter = suggestions.begin(); 291 for (size_t i = 0; i < suggestions.size(); ++i)
290 iter != suggestions.end(); ++iter) { 292 suggestions_.append(webkit_glue::WebStringToString(suggestions[i]));
291 suggestions_.push_back(webkit_glue::StdWStringToString(*iter));
292 }
293 // Try to preserve selection if possible. 293 // Try to preserve selection if possible.
294 if (selected_index_ >= static_cast<int>(suggestions.size())) 294 if (selected_index_ >= static_cast<int>(suggestions.size()))
295 selected_index_ = -1; 295 selected_index_ = -1;
296 } 296 }
297 297
298 void RemoveItemAtIndex(int index) { 298 void RemoveItemAtIndex(int index) {
299 DCHECK(index >= 0 && index < static_cast<int>(suggestions_.size())); 299 DCHECK(index >= 0 && index < static_cast<int>(suggestions_.size()));
300 suggestions_.erase(suggestions_.begin() + index); 300 suggestions_.remove(index);
301 } 301 }
302 302
303 WebCore::HTMLInputElement* text_field() const { 303 WebCore::HTMLInputElement* text_field() const {
304 return text_field_.get(); 304 return text_field_.get();
305 } 305 }
306 306
307 WebCore::RenderStyle* GetTextFieldStyle() const { 307 WebCore::RenderStyle* GetTextFieldStyle() const {
308 WebCore::RenderStyle* style = text_field_->computedStyle(); 308 WebCore::RenderStyle* style = text_field_->computedStyle();
309 if (!style) { 309 if (!style) {
310 // It seems we can only have an NULL style in a TextField if the node is 310 // It seems we can only have an NULL style in a TextField if the node is
311 // dettached, in which case we the popup shoud not be showing. 311 // dettached, in which case we the popup shoud not be showing.
312 NOTREACHED() << "Please report this in http://crbug.com/7708 and include " 312 NOTREACHED() << "Please report this in http://crbug.com/7708 and include "
313 "the page you were visiting."; 313 "the page you were visiting.";
314 } 314 }
315 return style; 315 return style;
316 } 316 }
317 317
318 private: 318 private:
319 RefPtr<WebCore::HTMLInputElement> text_field_; 319 RefPtr<WebCore::HTMLInputElement> text_field_;
320 std::vector<WebCore::String> suggestions_; 320 Vector<WebCore::String> suggestions_;
321 int selected_index_; 321 int selected_index_;
322 WebViewImpl* webview_; 322 WebViewImpl* webview_;
323 scoped_ptr<PopupMenuStyle> style_; 323 scoped_ptr<PopupMenuStyle> style_;
324 }; 324 };
325 325
326 // Note that focusOnShow is false so that the autocomplete popup is shown not 326 // Note that focusOnShow is false so that the autocomplete popup is shown not
327 // activated. We need the page to still have focus so the user can keep typing 327 // activated. We need the page to still have focus so the user can keep typing
328 // while the popup is showing. 328 // while the popup is showing.
329 static const WebCore::PopupContainerSettings kAutocompletePopupSettings = { 329 static const WebCore::PopupContainerSettings kAutocompletePopupSettings = {
330 false, // focusOnShow 330 false, // focusOnShow
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 } 672 }
673 WebCore::Element* element = static_cast<WebCore::Element*>(node); 673 WebCore::Element* element = static_cast<WebCore::Element*>(node);
674 if (!element->hasLocalName(WebCore::HTMLNames::inputTag)) { 674 if (!element->hasLocalName(WebCore::HTMLNames::inputTag)) {
675 NOTREACHED(); 675 NOTREACHED();
676 return false; 676 return false;
677 } 677 }
678 678
679 int selected_index = autocomplete_popup_->selectedIndex(); 679 int selected_index = autocomplete_popup_->selectedIndex();
680 WebCore::HTMLInputElement* input_element = 680 WebCore::HTMLInputElement* input_element =
681 static_cast<WebCore::HTMLInputElement*>(element); 681 static_cast<WebCore::HTMLInputElement*>(element);
682 std::wstring name = webkit_glue::StringToStdWString(input_element->name()); 682 const WebString& name = webkit_glue::StringToWebString(
683 std::wstring value = webkit_glue::StringToStdWString( 683 input_element->name());
684 autocomplete_popup_client_->itemText(selected_index )); 684 const WebString& value = webkit_glue::StringToWebString(
685 delegate()->RemoveStoredAutofillEntry(name, value); 685 autocomplete_popup_client_->itemText(selected_index));
686 client()->removeAutofillSuggestions(name, value);
686 // Update the entries in the currently showing popup to reflect the 687 // Update the entries in the currently showing popup to reflect the
687 // deletion. 688 // deletion.
688 autocomplete_popup_client_->RemoveItemAtIndex(selected_index); 689 autocomplete_popup_client_->RemoveItemAtIndex(selected_index);
689 RefreshAutofillPopup(); 690 RefreshAutofillPopup();
690 return false; 691 return false;
691 } 692 }
692 693
693 if (!autocomplete_popup_->isInterestedInEventForKey(event.windowsKeyCode)) 694 if (!autocomplete_popup_->isInterestedInEventForKey(event.windowsKeyCode))
694 return false; 695 return false;
695 696
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after
1666 WebAccessibilityObject WebViewImpl::accessibilityObject() { 1667 WebAccessibilityObject WebViewImpl::accessibilityObject() {
1667 if (!main_frame()) 1668 if (!main_frame())
1668 return WebAccessibilityObject(); 1669 return WebAccessibilityObject();
1669 1670
1670 WebCore::Document* document = main_frame()->frame()->document(); 1671 WebCore::Document* document = main_frame()->frame()->document();
1671 1672
1672 return AccessibilityObjectToWebAccessibilityObject( 1673 return AccessibilityObjectToWebAccessibilityObject(
1673 document->axObjectCache()->getOrCreate(document->renderer())); 1674 document->axObjectCache()->getOrCreate(document->renderer()));
1674 } 1675 }
1675 1676
1676 // WebView -------------------------------------------------------------------- 1677 void WebViewImpl::applyAutofillSuggestions(
1677 1678 const WebNode& node,
1678 bool WebViewImpl::setDropEffect(bool accept) { 1679 const WebVector<WebString>& suggestions,
1679 if (drag_target_dispatch_) { 1680 int default_suggestion_index) {
1680 drop_effect_ = accept ? DROP_EFFECT_COPY : DROP_EFFECT_NONE; 1681 if (!page_.get() || suggestions.isEmpty()) {
1681 return true;
1682 } else {
1683 return false;
1684 }
1685 }
1686
1687 void WebViewImpl::AutofillSuggestionsForNode(
1688 int64 node_id,
1689 const std::vector<std::wstring>& suggestions,
1690 int default_suggestion_index) {
1691 if (!page_.get() || suggestions.empty()) {
1692 HideAutoCompletePopup(); 1682 HideAutoCompletePopup();
1693 return; 1683 return;
1694 } 1684 }
1695 1685
1696 DCHECK(default_suggestion_index < static_cast<int>(suggestions.size())); 1686 DCHECK(default_suggestion_index < static_cast<int>(suggestions.size()));
1697 1687
1698 if (RefPtr<Frame> focused = page_->focusController()->focusedFrame()) { 1688 if (RefPtr<Frame> focused = page_->focusController()->focusedFrame()) {
1699 RefPtr<Document> document = focused->document(); 1689 RefPtr<Document> document = focused->document();
1700 if (!document.get()) { 1690 if (!document.get()) {
1701 HideAutoCompletePopup(); 1691 HideAutoCompletePopup();
1702 return; 1692 return;
1703 } 1693 }
1704 1694
1705 RefPtr<Node> focused_node = document->focusedNode(); 1695 RefPtr<Node> focused_node = document->focusedNode();
1706 // If the node for which we queried the autofill suggestions is not the 1696 // If the node for which we queried the autofill suggestions is not the
1707 // focused node, then we have nothing to do. 1697 // focused node, then we have nothing to do.
1708 // TODO(jcampan): also check the carret is at the end and that the text has 1698 // TODO(jcampan): also check the carret is at the end and that the text has
1709 // not changed. 1699 // not changed.
1710 if (!focused_node.get() || 1700 if (!focused_node.get() ||
1711 reinterpret_cast<int64>(focused_node.get()) != node_id) { 1701 focused_node != webkit_glue::WebNodeToNode(node)) {
1712 HideAutoCompletePopup(); 1702 HideAutoCompletePopup();
1713 return; 1703 return;
1714 } 1704 }
1715 1705
1716 if (!focused_node->hasTagName(WebCore::HTMLNames::inputTag)) { 1706 if (!focused_node->hasTagName(WebCore::HTMLNames::inputTag)) {
1717 NOTREACHED(); 1707 NOTREACHED();
1718 return; 1708 return;
1719 } 1709 }
1720 1710
1721 WebCore::HTMLInputElement* input_elem = 1711 WebCore::HTMLInputElement* input_elem =
(...skipping 16 matching lines...) Expand all
1738 autocomplete_popup_client_->SetSuggestions(suggestions); 1728 autocomplete_popup_client_->SetSuggestions(suggestions);
1739 RefreshAutofillPopup(); 1729 RefreshAutofillPopup();
1740 } else { 1730 } else {
1741 autocomplete_popup_->show(focused_node->getRect(), 1731 autocomplete_popup_->show(focused_node->getRect(),
1742 focused_node->ownerDocument()->view(), 0); 1732 focused_node->ownerDocument()->view(), 0);
1743 autocomplete_popup_showing_ = true; 1733 autocomplete_popup_showing_ = true;
1744 } 1734 }
1745 } 1735 }
1746 } 1736 }
1747 1737
1738 void WebViewImpl::hideAutofillPopup() {
1739 HideAutoCompletePopup();
1740 }
1741
1742 // WebView --------------------------------------------------------------------
1743
1744 bool WebViewImpl::setDropEffect(bool accept) {
1745 if (drag_target_dispatch_) {
1746 drop_effect_ = accept ? DROP_EFFECT_COPY : DROP_EFFECT_NONE;
1747 return true;
1748 } else {
1749 return false;
1750 }
1751 }
1752
1748 WebDevToolsAgent* WebViewImpl::GetWebDevToolsAgent() { 1753 WebDevToolsAgent* WebViewImpl::GetWebDevToolsAgent() {
1749 return GetWebDevToolsAgentImpl(); 1754 return GetWebDevToolsAgentImpl();
1750 } 1755 }
1751 1756
1752 WebDevToolsAgentImpl* WebViewImpl::GetWebDevToolsAgentImpl() { 1757 WebDevToolsAgentImpl* WebViewImpl::GetWebDevToolsAgentImpl() {
1753 return devtools_agent_.get(); 1758 return devtools_agent_.get();
1754 } 1759 }
1755 1760
1756 void WebViewImpl::setIsTransparent(bool is_transparent) { 1761 void WebViewImpl::setIsTransparent(bool is_transparent) {
1757 // Set any existing frames to be transparent. 1762 // Set any existing frames to be transparent.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1869 } 1874 }
1870 1875
1871 #if ENABLE(NOTIFICATIONS) 1876 #if ENABLE(NOTIFICATIONS)
1872 WebKit::NotificationPresenterImpl* WebViewImpl::GetNotificationPresenter() { 1877 WebKit::NotificationPresenterImpl* WebViewImpl::GetNotificationPresenter() {
1873 if (!notification_presenter_.isInitialized() && client()) 1878 if (!notification_presenter_.isInitialized() && client())
1874 notification_presenter_.initialize(client()->notificationPresenter()); 1879 notification_presenter_.initialize(client()->notificationPresenter());
1875 return &notification_presenter_; 1880 return &notification_presenter_;
1876 } 1881 }
1877 #endif 1882 #endif
1878 1883
1879 void WebViewImpl::HideAutofillPopup() {
1880 HideAutoCompletePopup();
1881 }
1882
1883 void WebViewImpl::RefreshAutofillPopup() { 1884 void WebViewImpl::RefreshAutofillPopup() {
1884 DCHECK(autocomplete_popup_showing_); 1885 DCHECK(autocomplete_popup_showing_);
1885 1886
1886 // Hide the popup if it has become empty. 1887 // Hide the popup if it has become empty.
1887 if (autocomplete_popup_client_->listSize() == 0) { 1888 if (autocomplete_popup_client_->listSize() == 0) {
1888 HideAutoCompletePopup(); 1889 HideAutoCompletePopup();
1889 return; 1890 return;
1890 } 1891 }
1891 1892
1892 IntRect old_bounds = autocomplete_popup_->boundsRect(); 1893 IntRect old_bounds = autocomplete_popup_->boundsRect();
(...skipping 27 matching lines...) Expand all
1920 hitTestResultAtPoint(doc_point, false); 1921 hitTestResultAtPoint(doc_point, false);
1921 } 1922 }
1922 1923
1923 void WebViewImpl::setTabsToLinks(bool enable) { 1924 void WebViewImpl::setTabsToLinks(bool enable) {
1924 tabs_to_links_ = enable; 1925 tabs_to_links_ = enable;
1925 } 1926 }
1926 1927
1927 bool WebViewImpl::tabsToLinks() const { 1928 bool WebViewImpl::tabsToLinks() const {
1928 return tabs_to_links_; 1929 return tabs_to_links_;
1929 } 1930 }
OLDNEW
« no previous file with comments | « webkit/glue/webview_impl.h ('k') | webkit/tools/test_shell/test_webview_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698