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

Side by Side Diff: Source/WebCore/page/FocusController.cpp

Issue 7714029: Merge 93514 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/835/
Patch Set: Created 9 years, 4 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
« no previous file with comments | « LayoutTests/fast/frames/focus-controller-crash-change-event-expected.txt ('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 /* 1 /*
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nuanti Ltd. 3 * Copyright (C) 2008 Nuanti Ltd.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 239
240 Node* currentNode = document->focusedNode(); 240 Node* currentNode = document->focusedNode();
241 // FIXME: Not quite correct when it comes to focus transitions leaving/enter ing the WebView itself 241 // FIXME: Not quite correct when it comes to focus transitions leaving/enter ing the WebView itself
242 bool caretBrowsing = focusedOrMainFrame()->settings()->caretBrowsingEnabled( ); 242 bool caretBrowsing = focusedOrMainFrame()->settings()->caretBrowsingEnabled( );
243 243
244 if (caretBrowsing && !currentNode) 244 if (caretBrowsing && !currentNode)
245 currentNode = frame->selection()->start().deprecatedNode(); 245 currentNode = frame->selection()->start().deprecatedNode();
246 246
247 document->updateLayoutIgnorePendingStylesheets(); 247 document->updateLayoutIgnorePendingStylesheets();
248 248
249 Node* node = findFocusableNodeAcrossTreeScope(direction, currentNode ? curre ntNode->treeScope() : document, currentNode, event); 249 RefPtr<Node> node = findFocusableNodeAcrossTreeScope(direction, currentNode ? currentNode->treeScope() : document, currentNode, event);
250 250
251 if (!node) { 251 if (!node) {
252 // We didn't find a node to focus, so we should try to pass focus to Chr ome. 252 // We didn't find a node to focus, so we should try to pass focus to Chr ome.
253 if (!initialFocus && m_page->chrome()->canTakeFocus(direction)) { 253 if (!initialFocus && m_page->chrome()->canTakeFocus(direction)) {
254 document->setFocusedNode(0); 254 document->setFocusedNode(0);
255 setFocusedFrame(0); 255 setFocusedFrame(0);
256 m_page->chrome()->takeFocus(direction); 256 m_page->chrome()->takeFocus(direction);
257 return true; 257 return true;
258 } 258 }
259 259
260 // Chrome doesn't want focus, so we should wrap focus. 260 // Chrome doesn't want focus, so we should wrap focus.
261 node = findFocusableNode(direction, m_page->mainFrame()->document(), 0, event); 261 node = findFocusableNode(direction, m_page->mainFrame()->document(), 0, event);
262 node = findFocusableNodeDecendingDownIntoFrameDocumentOrShadowRoot(direc tion, node, event); 262 node = findFocusableNodeDecendingDownIntoFrameDocumentOrShadowRoot(direc tion, node.get(), event);
263 263
264 if (!node) 264 if (!node)
265 return false; 265 return false;
266 } 266 }
267 267
268 ASSERT(node); 268 ASSERT(node);
269 269
270 if (node == document->focusedNode()) 270 if (node == document->focusedNode())
271 // Focus wrapped around to the same node. 271 // Focus wrapped around to the same node.
272 return true; 272 return true;
273 273
274 if (!node->isElementNode()) 274 if (!node->isElementNode())
275 // FIXME: May need a way to focus a document here. 275 // FIXME: May need a way to focus a document here.
276 return false; 276 return false;
277 277
278 if (node->isFrameOwnerElement()) { 278 if (node->isFrameOwnerElement()) {
279 // We focus frames rather than frame owners. 279 // We focus frames rather than frame owners.
280 // FIXME: We should not focus frames that have no scrollbars, as focusin g them isn't useful to the user. 280 // FIXME: We should not focus frames that have no scrollbars, as focusin g them isn't useful to the user.
281 HTMLFrameOwnerElement* owner = static_cast<HTMLFrameOwnerElement*>(node) ; 281 HTMLFrameOwnerElement* owner = static_cast<HTMLFrameOwnerElement*>(node. get());
282 if (!owner->contentFrame()) 282 if (!owner->contentFrame())
283 return false; 283 return false;
284 284
285 document->setFocusedNode(0); 285 document->setFocusedNode(0);
286 setFocusedFrame(owner->contentFrame()); 286 setFocusedFrame(owner->contentFrame());
287 return true; 287 return true;
288 } 288 }
289 289
290 // FIXME: It would be nice to just be able to call setFocusedNode(node) here , but we can't do 290 // FIXME: It would be nice to just be able to call setFocusedNode(node) here , but we can't do
291 // that because some elements (e.g. HTMLInputElement and HTMLTextAreaElement ) do extra work in 291 // that because some elements (e.g. HTMLInputElement and HTMLTextAreaElement ) do extra work in
292 // their focus() methods. 292 // their focus() methods.
293 293
294 Document* newDocument = node->document(); 294 Document* newDocument = node->document();
295 295
296 if (newDocument != document) 296 if (newDocument != document)
297 // Focus is going away from this document, so clear the focused node. 297 // Focus is going away from this document, so clear the focused node.
298 document->setFocusedNode(0); 298 document->setFocusedNode(0);
299 299
300 if (newDocument) 300 if (newDocument)
301 setFocusedFrame(newDocument->frame()); 301 setFocusedFrame(newDocument->frame());
302 302
303 if (caretBrowsing) { 303 if (caretBrowsing) {
304 Position position = firstPositionInOrBeforeNode(node); 304 Position position = firstPositionInOrBeforeNode(node.get());
305 VisibleSelection newSelection(position, position, DOWNSTREAM); 305 VisibleSelection newSelection(position, position, DOWNSTREAM);
306 if (frame->selection()->shouldChangeSelection(newSelection)) 306 if (frame->selection()->shouldChangeSelection(newSelection))
307 frame->selection()->setSelection(newSelection); 307 frame->selection()->setSelection(newSelection);
308 } 308 }
309 309
310 static_cast<Element*>(node)->focus(false); 310 static_cast<Element*>(node.get())->focus(false);
311 return true; 311 return true;
312 } 312 }
313 313
314 static inline Node* ownerOfTreeScope(TreeScope* scope) 314 static inline Node* ownerOfTreeScope(TreeScope* scope)
315 { 315 {
316 ASSERT(scope); 316 ASSERT(scope);
317 if (scope->isShadowRoot()) 317 if (scope->isShadowRoot())
318 return scope->shadowHost(); 318 return scope->shadowHost();
319 if (scope->document()->frame()) 319 if (scope->document()->frame())
320 return scope->document()->frame()->ownerElement(); 320 return scope->document()->frame()->ownerElement();
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b order */); 769 startingRect = nodeRectInAbsoluteCoordinates(container, true /* ignore b order */);
770 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(direct ion, container); 770 container = scrollableEnclosingBoxOrParentFrameForNodeInDirection(direct ion, container);
771 if (container && container->isDocumentNode()) 771 if (container && container->isDocumentNode())
772 static_cast<Document*>(container)->updateLayoutIgnorePendingStyleshe ets(); 772 static_cast<Document*>(container)->updateLayoutIgnorePendingStyleshe ets();
773 } while (!consumed && container); 773 } while (!consumed && container);
774 774
775 return consumed; 775 return consumed;
776 } 776 }
777 777
778 } // namespace WebCore 778 } // namespace WebCore
OLDNEW
« no previous file with comments | « LayoutTests/fast/frames/focus-controller-crash-change-event-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698