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

Side by Side Diff: chrome/renderer/render_view.cc

Issue 3474007: Forward textfield focus event to the browser. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Fixed merge conflict Created 10 years, 1 month 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
« no previous file with comments | « chrome/renderer/render_view.h ('k') | no next file » | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/renderer/render_view.h" 5 #include "chrome/renderer/render_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 #include "net/base/net_errors.h" 102 #include "net/base/net_errors.h"
103 #include "skia/ext/bitmap_platform_device.h" 103 #include "skia/ext/bitmap_platform_device.h"
104 #include "skia/ext/image_operations.h" 104 #include "skia/ext/image_operations.h"
105 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h" 105 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
106 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h" 106 #include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
107 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" 107 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
108 #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h" 108 #include "third_party/WebKit/WebKit/chromium/public/WebDataSource.h"
109 #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h" 109 #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
110 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" 110 #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h"
111 #include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" 111 #include "third_party/WebKit/WebKit/chromium/public/WebDragData.h"
112 #include "third_party/WebKit/WebKit/chromium/public/WebElement.h"
112 #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h" 113 #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h"
113 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h" 114 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystem.h"
114 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h" 115 #include "third_party/WebKit/WebKit/chromium/public/WebFileSystemCallbacks.h"
115 #include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h" 116 #include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h"
116 #include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h" 117 #include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h"
117 #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" 118 #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
118 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" 119 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
119 #include "third_party/WebKit/WebKit/chromium/public/WebGraphicsContext3D.h" 120 #include "third_party/WebKit/WebKit/chromium/public/WebGraphicsContext3D.h"
120 #include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h" 121 #include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h"
121 #include "third_party/WebKit/WebKit/chromium/public/WebImage.h" 122 #include "third_party/WebKit/WebKit/chromium/public/WebImage.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 using WebKit::WebContextMenuData; 197 using WebKit::WebContextMenuData;
197 using WebKit::WebCookieJar; 198 using WebKit::WebCookieJar;
198 using WebKit::WebData; 199 using WebKit::WebData;
199 using WebKit::WebDataSource; 200 using WebKit::WebDataSource;
200 using WebKit::WebDevToolsAgent; 201 using WebKit::WebDevToolsAgent;
201 using WebKit::WebDocument; 202 using WebKit::WebDocument;
202 using WebKit::WebDragData; 203 using WebKit::WebDragData;
203 using WebKit::WebDragOperation; 204 using WebKit::WebDragOperation;
204 using WebKit::WebDragOperationsMask; 205 using WebKit::WebDragOperationsMask;
205 using WebKit::WebEditingAction; 206 using WebKit::WebEditingAction;
207 using WebKit::WebElement;
206 using WebKit::WebExternalPopupMenu; 208 using WebKit::WebExternalPopupMenu;
207 using WebKit::WebExternalPopupMenuClient; 209 using WebKit::WebExternalPopupMenuClient;
208 using WebKit::WebFileChooserCompletion; 210 using WebKit::WebFileChooserCompletion;
209 using WebKit::WebFileSystem; 211 using WebKit::WebFileSystem;
210 using WebKit::WebFileSystemCallbacks; 212 using WebKit::WebFileSystemCallbacks;
211 using WebKit::WebFindOptions; 213 using WebKit::WebFindOptions;
212 using WebKit::WebFormControlElement; 214 using WebKit::WebFormControlElement;
213 using WebKit::WebFormElement; 215 using WebKit::WebFormElement;
214 using WebKit::WebFrame; 216 using WebKit::WebFrame;
215 using WebKit::WebHistoryItem; 217 using WebKit::WebHistoryItem;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 // the languages CLD can detect. As a result, it'll return the invalid 402 // the languages CLD can detect. As a result, it'll return the invalid
401 // language code for tradtional Chinese among others. 403 // language code for tradtional Chinese among others.
402 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and 404 // |LanguageCodeWithDialect| will go through ISO 639-1, ISO-639-2 and
403 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN 405 // 'other' tables to do the 'right' thing. In addition, it'll return zh-CN
404 // for Simplified Chinese. 406 // for Simplified Chinese.
405 language = LanguageCodeWithDialects(cld_language); 407 language = LanguageCodeWithDialects(cld_language);
406 } 408 }
407 return language; 409 return language;
408 } 410 }
409 411
412 // Returns true if the parameter node is a textfield, text area or a content
413 // editable div.
414 static bool IsEditableNode(const WebNode& node) {
415 bool is_editable_node = false;
416 if (!node.isNull()) {
417 if (node.isContentEditable()) {
418 is_editable_node = true;
419 } else if (node.isElementNode()) {
420 is_editable_node =
421 node.toConst<WebElement>().isTextFormControlElement();
422 }
423 }
424 return is_editable_node;
425 }
426
410 static bool WebAccessibilityNotificationToViewHostMsg( 427 static bool WebAccessibilityNotificationToViewHostMsg(
411 WebAccessibilityNotification notification, 428 WebAccessibilityNotification notification,
412 ViewHostMsg_AccessibilityNotification_Params::NotificationType* type) { 429 ViewHostMsg_AccessibilityNotification_Params::NotificationType* type) {
413 switch (notification) { 430 switch (notification) {
414 case WebKit::WebAccessibilityNotificationCheckedStateChanged: 431 case WebKit::WebAccessibilityNotificationCheckedStateChanged:
415 *type = ViewHostMsg_AccessibilityNotification_Params:: 432 *type = ViewHostMsg_AccessibilityNotification_Params::
416 NOTIFICATION_TYPE_CHECK_STATE_CHANGED; 433 NOTIFICATION_TYPE_CHECK_STATE_CHANGED;
417 break; 434 break;
418 case WebKit::WebAccessibilityNotificationChildrenChanged: 435 case WebKit::WebAccessibilityNotificationChildrenChanged:
419 *type = ViewHostMsg_AccessibilityNotification_Params:: 436 *type = ViewHostMsg_AccessibilityNotification_Params::
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver) 795 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragOver, OnDragTargetDragOver)
779 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave) 796 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDragLeave, OnDragTargetDragLeave)
780 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop) 797 IPC_MESSAGE_HANDLER(ViewMsg_DragTargetDrop, OnDragTargetDrop)
781 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings) 798 IPC_MESSAGE_HANDLER(ViewMsg_AllowBindings, OnAllowBindings)
782 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty) 799 IPC_MESSAGE_HANDLER(ViewMsg_SetDOMUIProperty, OnSetDOMUIProperty)
783 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved, 800 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceEndedOrMoved,
784 OnDragSourceEndedOrMoved) 801 OnDragSourceEndedOrMoved)
785 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded, 802 IPC_MESSAGE_HANDLER(ViewMsg_DragSourceSystemDragEnded,
786 OnDragSourceSystemDragEnded) 803 OnDragSourceSystemDragEnded)
787 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus) 804 IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
805 IPC_MESSAGE_HANDLER(ViewMsg_ScrollFocusedEditableNodeIntoView,
806 OnScrollFocusedEditableNodeIntoView)
788 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck) 807 IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
789 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences) 808 IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
790 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL) 809 IPC_MESSAGE_HANDLER(ViewMsg_SetAltErrorPageURL, OnSetAltErrorPageURL)
791 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin) 810 IPC_MESSAGE_HANDLER(ViewMsg_InstallMissingPlugin, OnInstallMissingPlugin)
792 IPC_MESSAGE_HANDLER(ViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins) 811 IPC_MESSAGE_HANDLER(ViewMsg_LoadBlockedPlugins, OnLoadBlockedPlugins)
793 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse) 812 IPC_MESSAGE_HANDLER(ViewMsg_RunFileChooserResponse, OnFileChooserResponse)
794 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode) 813 IPC_MESSAGE_HANDLER(ViewMsg_EnableViewSourceMode, OnEnableViewSourceMode)
795 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage, 814 IPC_MESSAGE_HANDLER(ViewMsg_GetAllSavableResourceLinksForCurrentPage,
796 OnGetAllSavableResourceLinksForCurrentPage) 815 OnGetAllSavableResourceLinksForCurrentPage)
797 IPC_MESSAGE_HANDLER( 816 IPC_MESSAGE_HANDLER(
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
1351 WebString::fromUTF8("SelectAll")); 1370 WebString::fromUTF8("SelectAll"));
1352 UserMetricsRecordAction("SelectAll"); 1371 UserMetricsRecordAction("SelectAll");
1353 } 1372 }
1354 1373
1355 void RenderView::OnSetInitialFocus(bool reverse) { 1374 void RenderView::OnSetInitialFocus(bool reverse) {
1356 if (!webview()) 1375 if (!webview())
1357 return; 1376 return;
1358 webview()->setInitialFocus(reverse); 1377 webview()->setInitialFocus(reverse);
1359 } 1378 }
1360 1379
1380 void RenderView::OnScrollFocusedEditableNodeIntoView() {
1381 if (!webview())
1382 return;
1383 WebFrame* focused_frame = webview()->focusedFrame();
1384 if (focused_frame) {
1385 WebDocument doc = focused_frame->document();
1386 if (!doc.isNull()) {
1387 WebNode node = doc.focusedNode();
1388 if (IsEditableNode(node))
1389 // TODO(varunjain): Change webkit API to scroll a particular node into
1390 // view and use that API here instead.
1391 webview()->scrollFocusedNodeIntoView();
1392 }
1393 }
1394 }
1395
1361 /////////////////////////////////////////////////////////////////////////////// 1396 ///////////////////////////////////////////////////////////////////////////////
1362 1397
1363 void RenderView::SetContentSettings(const ContentSettings& settings) { 1398 void RenderView::SetContentSettings(const ContentSettings& settings) {
1364 current_content_settings_ = settings; 1399 current_content_settings_ = settings;
1365 } 1400 }
1366 1401
1367 // Tell the embedding application that the URL of the active page has changed 1402 // Tell the embedding application that the URL of the active page has changed
1368 void RenderView::UpdateURL(WebFrame* frame) { 1403 void RenderView::UpdateURL(WebFrame* frame) {
1369 WebDataSource* ds = frame->dataSource(); 1404 WebDataSource* ds = frame->dataSource();
1370 DCHECK(ds); 1405 DCHECK(ds);
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
2304 2339
2305 void RenderView::focusNext() { 2340 void RenderView::focusNext() {
2306 Send(new ViewHostMsg_TakeFocus(routing_id_, false)); 2341 Send(new ViewHostMsg_TakeFocus(routing_id_, false));
2307 } 2342 }
2308 2343
2309 void RenderView::focusPrevious() { 2344 void RenderView::focusPrevious() {
2310 Send(new ViewHostMsg_TakeFocus(routing_id_, true)); 2345 Send(new ViewHostMsg_TakeFocus(routing_id_, true));
2311 } 2346 }
2312 2347
2313 void RenderView::focusedNodeChanged(const WebNode& node) { 2348 void RenderView::focusedNodeChanged(const WebNode& node) {
2314 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_)); 2349 Send(new ViewHostMsg_FocusedNodeChanged(routing_id_, IsEditableNode(node)));
2315 2350
2316 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) { 2351 if (WebAccessibilityCache::accessibilityEnabled() && node.isNull()) {
2317 // TODO(ctguil): Make WebKit send this notification. 2352 // TODO(ctguil): Make WebKit send this notification.
2318 // When focus is cleared notify accessibility that the document is focused. 2353 // When focus is cleared notify accessibility that the document is focused.
2319 postAccessibilityNotification( 2354 postAccessibilityNotification(
2320 webview()->accessibilityObject(), 2355 webview()->accessibilityObject(),
2321 WebKit::WebAccessibilityNotificationFocusedUIElementChanged); 2356 WebKit::WebAccessibilityNotificationFocusedUIElementChanged);
2322 } 2357 }
2323 } 2358 }
2324 2359
(...skipping 3765 matching lines...) Expand 10 before | Expand all | Expand 10 after
6090 IPC::PlatformFileForTransitToPlatformFile(file_for_transit), 6125 IPC::PlatformFileForTransitToPlatformFile(file_for_transit),
6091 message_id); 6126 message_id);
6092 } 6127 }
6093 6128
6094 #if defined(OS_MACOSX) 6129 #if defined(OS_MACOSX)
6095 void RenderView::OnSelectPopupMenuItem(int selected_index) { 6130 void RenderView::OnSelectPopupMenuItem(int selected_index) {
6096 external_popup_menu_->DidSelectItem(selected_index); 6131 external_popup_menu_->DidSelectItem(selected_index);
6097 external_popup_menu_.reset(); 6132 external_popup_menu_.reset();
6098 } 6133 }
6099 #endif 6134 #endif
OLDNEW
« no previous file with comments | « chrome/renderer/render_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698