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

Side by Side Diff: Source/core/html/RadioInputType.cpp

Issue 23819007: Have Node::document() return a reference instead of a pointer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 3 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 | « Source/core/html/PasswordInputType.cpp ('k') | Source/core/html/RangeInputType.cpp » ('j') | 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) 2005, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Google Inc. All rights reserved. 3 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 return; 68 return;
69 const String& key = event->keyIdentifier(); 69 const String& key = event->keyIdentifier();
70 if (key != "Up" && key != "Down" && key != "Left" && key != "Right") 70 if (key != "Up" && key != "Down" && key != "Left" && key != "Right")
71 return; 71 return;
72 72
73 // Left and up mean "previous radio button". 73 // Left and up mean "previous radio button".
74 // Right and down mean "next radio button". 74 // Right and down mean "next radio button".
75 // Tested in WinIE, and even for RTL, left still means previous radio button (and so moves 75 // Tested in WinIE, and even for RTL, left still means previous radio button (and so moves
76 // to the right). Seems strange, but we'll match it. 76 // to the right). Seems strange, but we'll match it.
77 // However, when using Spatial Navigation, we need to be able to navigate wi thout changing the selection. 77 // However, when using Spatial Navigation, we need to be able to navigate wi thout changing the selection.
78 Document* document = element()->document(); 78 Document& document = element()->document();
79 if (isSpatialNavigationEnabled(document->frame())) 79 if (isSpatialNavigationEnabled(document.frame()))
80 return; 80 return;
81 bool forward = (key == "Down" || key == "Right"); 81 bool forward = (key == "Down" || key == "Right");
82 82
83 // We can only stay within the form's children if the form hasn't been demot ed to a leaf because 83 // We can only stay within the form's children if the form hasn't been demot ed to a leaf because
84 // of malformed HTML. 84 // of malformed HTML.
85 Node* node = element(); 85 Node* node = element();
86 while ((node = (forward ? NodeTraversal::next(node) : NodeTraversal::previou s(node)))) { 86 while ((node = (forward ? NodeTraversal::next(node) : NodeTraversal::previou s(node)))) {
87 // Once we encounter a form element, we know we're through. 87 // Once we encounter a form element, we know we're through.
88 if (node->hasTagName(formTag)) 88 if (node->hasTagName(formTag))
89 break; 89 break;
90 // Look for more radio buttons. 90 // Look for more radio buttons.
91 if (!node->hasTagName(inputTag)) 91 if (!node->hasTagName(inputTag))
92 continue; 92 continue;
93 HTMLInputElement* inputElement = toHTMLInputElement(node); 93 HTMLInputElement* inputElement = toHTMLInputElement(node);
94 if (inputElement->form() != element()->form()) 94 if (inputElement->form() != element()->form())
95 break; 95 break;
96 if (inputElement->isRadioButton() && inputElement->name() == element()-> name() && inputElement->isFocusable()) { 96 if (inputElement->isRadioButton() && inputElement->name() == element()-> name() && inputElement->isFocusable()) {
97 RefPtr<HTMLInputElement> protector(inputElement); 97 RefPtr<HTMLInputElement> protector(inputElement);
98 document->setFocusedElement(inputElement); 98 document.setFocusedElement(inputElement);
99 inputElement->dispatchSimulatedClick(event, SendNoEvents, DoNotShowP ressedLook); 99 inputElement->dispatchSimulatedClick(event, SendNoEvents, DoNotShowP ressedLook);
100 event->setDefaultHandled(); 100 event->setDefaultHandled();
101 return; 101 return;
102 } 102 }
103 } 103 }
104 } 104 }
105 105
106 void RadioInputType::handleKeyupEvent(KeyboardEvent* event) 106 void RadioInputType::handleKeyupEvent(KeyboardEvent* event)
107 { 107 {
108 const String& key = event->keyIdentifier(); 108 const String& key = event->keyIdentifier();
109 if (key != "U+0020") 109 if (key != "U+0020")
110 return; 110 return;
111 // If an unselected radio is tabbed into (because the entire group has nothi ng 111 // If an unselected radio is tabbed into (because the entire group has nothi ng
112 // checked, or because of some explicit .focus() call), then allow space to check it. 112 // checked, or because of some explicit .focus() call), then allow space to check it.
113 if (element()->checked()) 113 if (element()->checked())
114 return; 114 return;
115 dispatchSimulatedClickIfActive(event); 115 dispatchSimulatedClickIfActive(event);
116 } 116 }
117 117
118 bool RadioInputType::isKeyboardFocusable() const 118 bool RadioInputType::isKeyboardFocusable() const
119 { 119 {
120 if (!InputType::isKeyboardFocusable()) 120 if (!InputType::isKeyboardFocusable())
121 return false; 121 return false;
122 122
123 // When using Spatial Navigation, every radio button should be focusable. 123 // When using Spatial Navigation, every radio button should be focusable.
124 if (isSpatialNavigationEnabled(element()->document()->frame())) 124 if (isSpatialNavigationEnabled(element()->document().frame()))
125 return true; 125 return true;
126 126
127 // Never allow keyboard tabbing to leave you in the same radio group. Alway s 127 // Never allow keyboard tabbing to leave you in the same radio group. Alway s
128 // skip any other elements in the group. 128 // skip any other elements in the group.
129 Element* currentFocusedElement = element()->document()->focusedElement(); 129 Element* currentFocusedElement = element()->document().focusedElement();
130 if (currentFocusedElement && currentFocusedElement->hasTagName(inputTag)) { 130 if (currentFocusedElement && currentFocusedElement->hasTagName(inputTag)) {
131 HTMLInputElement* focusedInput = toHTMLInputElement(currentFocusedElemen t); 131 HTMLInputElement* focusedInput = toHTMLInputElement(currentFocusedElemen t);
132 if (focusedInput->isRadioButton() && focusedInput->form() == element()-> form() && focusedInput->name() == element()->name()) 132 if (focusedInput->isRadioButton() && focusedInput->form() == element()-> form() && focusedInput->name() == element()->name())
133 return false; 133 return false;
134 } 134 }
135 135
136 // Allow keyboard focus if we're checked or if nothing in the group is check ed. 136 // Allow keyboard focus if we're checked or if nothing in the group is check ed.
137 return element()->checked() || !element()->checkedRadioButtonForGroup(); 137 return element()->checked() || !element()->checkedRadioButtonForGroup();
138 } 138 }
139 139
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 { 184 {
185 return true; 185 return true;
186 } 186 }
187 187
188 bool RadioInputType::supportsIndeterminateAppearance() const 188 bool RadioInputType::supportsIndeterminateAppearance() const
189 { 189 {
190 return false; 190 return false;
191 } 191 }
192 192
193 } // namespace WebCore 193 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/PasswordInputType.cpp ('k') | Source/core/html/RangeInputType.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698