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

Side by Side Diff: Source/core/page/PointerLockController.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/page/Page.cpp ('k') | Source/core/page/PrintContext.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) 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 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 return adoptPtr(new PointerLockController(page)); 44 return adoptPtr(new PointerLockController(page));
45 } 45 }
46 46
47 void PointerLockController::requestPointerLock(Element* target) 47 void PointerLockController::requestPointerLock(Element* target)
48 { 48 {
49 if (!target || !target->inDocument() || m_documentOfRemovedElementWhileWaiti ngForUnlock) { 49 if (!target || !target->inDocument() || m_documentOfRemovedElementWhileWaiti ngForUnlock) {
50 enqueueEvent(eventNames().webkitpointerlockerrorEvent, target); 50 enqueueEvent(eventNames().webkitpointerlockerrorEvent, target);
51 return; 51 return;
52 } 52 }
53 53
54 if (target->document()->isSandboxed(SandboxPointerLock)) { 54 if (target->document().isSandboxed(SandboxPointerLock)) {
55 // FIXME: This message should be moved off the console once a solution t o https://bugs.webkit.org/show_bug.cgi?id=103274 exists. 55 // FIXME: This message should be moved off the console once a solution t o https://bugs.webkit.org/show_bug.cgi?id=103274 exists.
56 target->document()->addConsoleMessage(SecurityMessageSource, ErrorMessag eLevel, "Blocked pointer lock on an element because the element's frame is sandb oxed and the 'allow-pointer-lock' permission is not set."); 56 target->document().addConsoleMessage(SecurityMessageSource, ErrorMessage Level, "Blocked pointer lock on an element because the element's frame is sandbo xed and the 'allow-pointer-lock' permission is not set.");
57 enqueueEvent(eventNames().webkitpointerlockerrorEvent, target); 57 enqueueEvent(eventNames().webkitpointerlockerrorEvent, target);
58 return; 58 return;
59 } 59 }
60 60
61 if (m_element) { 61 if (m_element) {
62 if (m_element->document() != target->document()) { 62 if (&m_element->document() != &target->document()) {
63 enqueueEvent(eventNames().webkitpointerlockerrorEvent, target); 63 enqueueEvent(eventNames().webkitpointerlockerrorEvent, target);
64 return; 64 return;
65 } 65 }
66 enqueueEvent(eventNames().webkitpointerlockchangeEvent, target); 66 enqueueEvent(eventNames().webkitpointerlockchangeEvent, target);
67 m_element = target; 67 m_element = target;
68 } else if (m_page->chrome().client().requestPointerLock()) { 68 } else if (m_page->chrome().client().requestPointerLock()) {
69 m_lockPending = true; 69 m_lockPending = true;
70 m_element = target; 70 m_element = target;
71 } else { 71 } else {
72 enqueueEvent(eventNames().webkitpointerlockerrorEvent, target); 72 enqueueEvent(eventNames().webkitpointerlockerrorEvent, target);
73 } 73 }
74 } 74 }
75 75
76 void PointerLockController::requestPointerUnlock() 76 void PointerLockController::requestPointerUnlock()
77 { 77 {
78 return m_page->chrome().client().requestPointerUnlock(); 78 return m_page->chrome().client().requestPointerUnlock();
79 } 79 }
80 80
81 void PointerLockController::elementRemoved(Element* element) 81 void PointerLockController::elementRemoved(Element* element)
82 { 82 {
83 if (m_element == element) { 83 if (m_element == element) {
84 m_documentOfRemovedElementWhileWaitingForUnlock = m_element->document(); 84 m_documentOfRemovedElementWhileWaitingForUnlock = &m_element->document() ;
85 // Set element null immediately to block any future interaction with it 85 // Set element null immediately to block any future interaction with it
86 // including mouse events received before the unlock completes. 86 // including mouse events received before the unlock completes.
87 clearElement(); 87 clearElement();
88 requestPointerUnlock(); 88 requestPointerUnlock();
89 } 89 }
90 } 90 }
91 91
92 void PointerLockController::documentDetached(Document* document) 92 void PointerLockController::documentDetached(Document* document)
93 { 93 {
94 if (m_element && m_element->document() == document) { 94 if (m_element && &m_element->document() == document) {
95 clearElement(); 95 clearElement();
96 requestPointerUnlock(); 96 requestPointerUnlock();
97 } 97 }
98 } 98 }
99 99
100 bool PointerLockController::lockPending() const 100 bool PointerLockController::lockPending() const
101 { 101 {
102 return m_lockPending; 102 return m_lockPending;
103 } 103 }
104 104
105 Element* PointerLockController::element() const 105 Element* PointerLockController::element() const
106 { 106 {
107 return m_element.get(); 107 return m_element.get();
108 } 108 }
109 109
110 void PointerLockController::didAcquirePointerLock() 110 void PointerLockController::didAcquirePointerLock()
111 { 111 {
112 enqueueEvent(eventNames().webkitpointerlockchangeEvent, m_element.get()); 112 enqueueEvent(eventNames().webkitpointerlockchangeEvent, m_element.get());
113 m_lockPending = false; 113 m_lockPending = false;
114 } 114 }
115 115
116 void PointerLockController::didNotAcquirePointerLock() 116 void PointerLockController::didNotAcquirePointerLock()
117 { 117 {
118 enqueueEvent(eventNames().webkitpointerlockerrorEvent, m_element.get()); 118 enqueueEvent(eventNames().webkitpointerlockerrorEvent, m_element.get());
119 clearElement(); 119 clearElement();
120 } 120 }
121 121
122 void PointerLockController::didLosePointerLock() 122 void PointerLockController::didLosePointerLock()
123 { 123 {
124 enqueueEvent(eventNames().webkitpointerlockchangeEvent, m_element ? m_elemen t->document() : m_documentOfRemovedElementWhileWaitingForUnlock.get()); 124 enqueueEvent(eventNames().webkitpointerlockchangeEvent, m_element ? &m_eleme nt->document() : m_documentOfRemovedElementWhileWaitingForUnlock.get());
125 clearElement(); 125 clearElement();
126 m_documentOfRemovedElementWhileWaitingForUnlock = 0; 126 m_documentOfRemovedElementWhileWaitingForUnlock = 0;
127 } 127 }
128 128
129 void PointerLockController::dispatchLockedMouseEvent(const PlatformMouseEvent& e vent, const AtomicString& eventType) 129 void PointerLockController::dispatchLockedMouseEvent(const PlatformMouseEvent& e vent, const AtomicString& eventType)
130 { 130 {
131 if (!m_element || !m_element->document()->frame()) 131 if (!m_element || !m_element->document().frame())
132 return; 132 return;
133 133
134 m_element->dispatchMouseEvent(event, eventType, event.clickCount()); 134 m_element->dispatchMouseEvent(event, eventType, event.clickCount());
135 135
136 // Create click events 136 // Create click events
137 if (eventType == eventNames().mouseupEvent) 137 if (eventType == eventNames().mouseupEvent)
138 m_element->dispatchMouseEvent(event, eventNames().clickEvent, event.clic kCount()); 138 m_element->dispatchMouseEvent(event, eventNames().clickEvent, event.clic kCount());
139 } 139 }
140 140
141 void PointerLockController::clearElement() 141 void PointerLockController::clearElement()
142 { 142 {
143 m_lockPending = false; 143 m_lockPending = false;
144 m_element = 0; 144 m_element = 0;
145 } 145 }
146 146
147 void PointerLockController::enqueueEvent(const AtomicString& type, Element* elem ent) 147 void PointerLockController::enqueueEvent(const AtomicString& type, Element* elem ent)
148 { 148 {
149 if (element) 149 if (element)
150 enqueueEvent(type, element->document()); 150 enqueueEvent(type, &element->document());
151 } 151 }
152 152
153 void PointerLockController::enqueueEvent(const AtomicString& type, Document* doc ument) 153 void PointerLockController::enqueueEvent(const AtomicString& type, Document* doc ument)
154 { 154 {
155 if (document) 155 if (document)
156 document->enqueueDocumentEvent(Event::createBubble(type)); 156 document->enqueueDocumentEvent(Event::createBubble(type));
157 } 157 }
158 158
159 } // namespace WebCore 159 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/page/Page.cpp ('k') | Source/core/page/PrintContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698