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

Side by Side Diff: Source/modules/vibration/NavigatorVibration.cpp

Issue 171333003: Pass implementation object to supplemental classes by reference (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Samsung Electronics 2 * Copyright (C) 2012 Samsung Electronics
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 13 matching lines...) Expand all
24 #include "core/frame/Frame.h" 24 #include "core/frame/Frame.h"
25 #include "core/page/PageVisibilityState.h" 25 #include "core/page/PageVisibilityState.h"
26 #include "public/platform/Platform.h" 26 #include "public/platform/Platform.h"
27 #include "public/platform/WebVibration.h" 27 #include "public/platform/WebVibration.h"
28 28
29 namespace WebCore { 29 namespace WebCore {
30 30
31 // Maximum number of entries in a vibration pattern. 31 // Maximum number of entries in a vibration pattern.
32 const unsigned kVibrationPatternLengthMax = 99; 32 const unsigned kVibrationPatternLengthMax = 99;
33 33
34 NavigatorVibration::NavigatorVibration(Page* page) 34 NavigatorVibration::NavigatorVibration(Page& page)
35 : PageLifecycleObserver(page) 35 : PageLifecycleObserver(&page)
36 , m_timerStart(this, &NavigatorVibration::timerStartFired) 36 , m_timerStart(this, &NavigatorVibration::timerStartFired)
37 , m_timerStop(this, &NavigatorVibration::timerStopFired) 37 , m_timerStop(this, &NavigatorVibration::timerStopFired)
38 , m_isVibrating(false) 38 , m_isVibrating(false)
39 { 39 {
40 } 40 }
41 41
42 NavigatorVibration::~NavigatorVibration() 42 NavigatorVibration::~NavigatorVibration()
43 { 43 {
44 if (m_isVibrating) 44 if (m_isVibrating)
45 cancelVibration(); 45 cancelVibration();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 cancelVibration(); 129 cancelVibration();
130 } 130 }
131 131
132 void NavigatorVibration::didCommitLoad(Frame* frame) 132 void NavigatorVibration::didCommitLoad(Frame* frame)
133 { 133 {
134 // A new load has been committed, which means the current page will be 134 // A new load has been committed, which means the current page will be
135 // unloaded. Cancel all running vibrations. 135 // unloaded. Cancel all running vibrations.
136 cancelVibration(); 136 cancelVibration();
137 } 137 }
138 138
139 bool NavigatorVibration::vibrate(Navigator* navigator, unsigned time) 139 bool NavigatorVibration::vibrate(Navigator& navigator, unsigned time)
140 { 140 {
141 VibrationPattern pattern; 141 VibrationPattern pattern;
142 pattern.append(time); 142 pattern.append(time);
143 return NavigatorVibration::vibrate(navigator, pattern); 143 return NavigatorVibration::vibrate(navigator, pattern);
144 } 144 }
145 145
146 bool NavigatorVibration::vibrate(Navigator* navigator, const VibrationPattern& p attern) 146 bool NavigatorVibration::vibrate(Navigator& navigator, const VibrationPattern& p attern)
147 { 147 {
148 Page* page = navigator->frame()->page(); 148 Page* page = navigator.frame()->page();
149 if (!page) 149 if (!page)
150 return false; 150 return false;
151 151
152 if (page->visibilityState() != PageVisibilityStateVisible) 152 if (page->visibilityState() != PageVisibilityStateVisible)
153 return false; 153 return false;
154 154
155 return NavigatorVibration::from(page)->vibrate(pattern); 155 return NavigatorVibration::from(*page).vibrate(pattern);
156 } 156 }
157 157
158 NavigatorVibration* NavigatorVibration::from(Page* page) 158 NavigatorVibration& NavigatorVibration::from(Page& page)
159 { 159 {
160 NavigatorVibration* navigatorVibration = static_cast<NavigatorVibration*>(Su pplement<Page>::from(page, supplementName())); 160 NavigatorVibration* navigatorVibration = static_cast<NavigatorVibration*>(Su pplement<Page>::from(page, supplementName()));
161 if (!navigatorVibration) { 161 if (!navigatorVibration) {
162 navigatorVibration = new NavigatorVibration(page); 162 navigatorVibration = new NavigatorVibration(page);
163 Supplement<Page>::provideTo(page, supplementName(), adoptPtr(navigatorVi bration)); 163 Supplement<Page>::provideTo(page, supplementName(), adoptPtr(navigatorVi bration));
164 } 164 }
165 return navigatorVibration; 165 return *navigatorVibration;
166 } 166 }
167 167
168 const char* NavigatorVibration::supplementName() 168 const char* NavigatorVibration::supplementName()
169 { 169 {
170 return "NavigatorVibration"; 170 return "NavigatorVibration";
171 } 171 }
172 172
173 } // namespace WebCore 173 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698