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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLDialogElement.cpp

Issue 2560553002: Add DialogShowParams to <dialog>'s show() and showModal() (Closed)
Patch Set: merge & rename Created 3 years, 12 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
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 14 matching lines...) Expand all
25 25
26 #include "core/html/HTMLDialogElement.h" 26 #include "core/html/HTMLDialogElement.h"
27 27
28 #include "bindings/core/v8/ExceptionState.h" 28 #include "bindings/core/v8/ExceptionState.h"
29 #include "core/dom/AXObjectCache.h" 29 #include "core/dom/AXObjectCache.h"
30 #include "core/dom/ExceptionCode.h" 30 #include "core/dom/ExceptionCode.h"
31 #include "core/dom/NodeTraversal.h" 31 #include "core/dom/NodeTraversal.h"
32 #include "core/events/Event.h" 32 #include "core/events/Event.h"
33 #include "core/frame/FrameView.h" 33 #include "core/frame/FrameView.h"
34 #include "core/frame/UseCounter.h" 34 #include "core/frame/UseCounter.h"
35 #include "core/html/DialogShowParams.h"
35 #include "core/html/HTMLFormControlElement.h" 36 #include "core/html/HTMLFormControlElement.h"
36 #include "core/style/ComputedStyle.h" 37 #include "core/style/ComputedStyle.h"
37 38
38 namespace blink { 39 namespace blink {
39 40
40 using namespace HTMLNames; 41 using namespace HTMLNames;
41 42
42 // This function chooses the focused element when show() or showModal() is 43 // This function chooses the focused element when show() or showModal() is
43 // invoked, as described in their spec. 44 // invoked, as described in their spec.
44 static void setFocusForDialog(HTMLDialogElement* dialog) { 45 static void setFocusForDialog(HTMLDialogElement* dialog) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if (m_centeringMode == NeedsCentering) 132 if (m_centeringMode == NeedsCentering)
132 setNotCentered(); 133 setNotCentered();
133 } 134 }
134 135
135 void HTMLDialogElement::scheduleCloseEvent() { 136 void HTMLDialogElement::scheduleCloseEvent() {
136 Event* event = Event::create(EventTypeNames::close); 137 Event* event = Event::create(EventTypeNames::close);
137 event->setTarget(this); 138 event->setTarget(this);
138 document().enqueueAnimationFrameEvent(event); 139 document().enqueueAnimationFrameEvent(event);
139 } 140 }
140 141
141 void HTMLDialogElement::show() { 142 void HTMLDialogElement::show(const DialogShowParams& showParams) {
142 if (fastHasAttribute(openAttr)) 143 if (fastHasAttribute(openAttr))
143 return; 144 return;
144 setBooleanAttribute(openAttr, true); 145 setBooleanAttribute(openAttr, true);
145 146
147 if (showParams.skipInitialFocus())
148 return;
149
146 // The layout must be updated here because setFocusForDialog calls 150 // The layout must be updated here because setFocusForDialog calls
147 // Element::isFocusable, which requires an up-to-date layout. 151 // Element::isFocusable, which requires an up-to-date layout.
148 document().updateStyleAndLayoutIgnorePendingStylesheets(); 152 document().updateStyleAndLayoutIgnorePendingStylesheets();
149
150 setFocusForDialog(this); 153 setFocusForDialog(this);
151 } 154 }
152 155
153 void HTMLDialogElement::showModal(ExceptionState& exceptionState) { 156 void HTMLDialogElement::showModal(const DialogShowParams& showParams,
157 ExceptionState& exceptionState) {
154 if (fastHasAttribute(openAttr)) { 158 if (fastHasAttribute(openAttr)) {
155 exceptionState.throwDOMException(InvalidStateError, 159 exceptionState.throwDOMException(InvalidStateError,
156 "The element already has an 'open' " 160 "The element already has an 'open' "
157 "attribute, and therefore cannot be " 161 "attribute, and therefore cannot be "
158 "opened modally."); 162 "opened modally.");
159 return; 163 return;
160 } 164 }
161 if (!isConnected()) { 165 if (!isConnected()) {
162 exceptionState.throwDOMException(InvalidStateError, 166 exceptionState.throwDOMException(InvalidStateError,
163 "The element is not in a Document."); 167 "The element is not in a Document.");
164 return; 168 return;
165 } 169 }
166 170
167 document().addToTopLayer(this); 171 document().addToTopLayer(this);
168 setBooleanAttribute(openAttr, true); 172 setBooleanAttribute(openAttr, true);
169 173
170 // Throw away the AX cache first, so the subsequent steps don't have a chance 174 // Throw away the AX cache first, so the subsequent steps don't have a chance
171 // of queuing up AX events on objects that would be invalidated when the cache 175 // of queuing up AX events on objects that would be invalidated when the cache
172 // is thrown away. 176 // is thrown away.
173 inertSubtreesChanged(document()); 177 inertSubtreesChanged(document());
174 178
175 forceLayoutForCentering(); 179 forceLayoutForCentering();
180
181 if (showParams.skipInitialFocus())
182 return;
183
176 setFocusForDialog(this); 184 setFocusForDialog(this);
177 } 185 }
178 186
179 void HTMLDialogElement::removedFrom(ContainerNode* insertionPoint) { 187 void HTMLDialogElement::removedFrom(ContainerNode* insertionPoint) {
180 HTMLElement::removedFrom(insertionPoint); 188 HTMLElement::removedFrom(insertionPoint);
181 setNotCentered(); 189 setNotCentered();
182 // FIXME: We should call inertSubtreesChanged() here. 190 // FIXME: We should call inertSubtreesChanged() here.
183 } 191 }
184 192
185 void HTMLDialogElement::setCentered(LayoutUnit centeredPosition) { 193 void HTMLDialogElement::setCentered(LayoutUnit centeredPosition) {
(...skipping 20 matching lines...) Expand all
206 void HTMLDialogElement::defaultEventHandler(Event* event) { 214 void HTMLDialogElement::defaultEventHandler(Event* event) {
207 if (event->type() == EventTypeNames::cancel) { 215 if (event->type() == EventTypeNames::cancel) {
208 closeDialog(); 216 closeDialog();
209 event->setDefaultHandled(); 217 event->setDefaultHandled();
210 return; 218 return;
211 } 219 }
212 HTMLElement::defaultEventHandler(event); 220 HTMLElement::defaultEventHandler(event);
213 } 221 }
214 222
215 } // namespace blink 223 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLDialogElement.h ('k') | third_party/WebKit/Source/core/html/HTMLDialogElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698