OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "ScreenOrientationController.h" |
| 7 |
| 8 #include "modules/screen_orientation/ScreenOrientationClient.h" |
| 9 |
| 10 namespace WebCore { |
| 11 |
| 12 ScreenOrientationController::ScreenOrientationController(ScreenOrientationClient
* client) |
| 13 : m_client(client) |
| 14 , m_orientation(OrientationPortraitPrimary) |
| 15 , m_hasClientForTest(false) |
| 16 { |
| 17 } |
| 18 |
| 19 PassOwnPtr<ScreenOrientationController> ScreenOrientationController::create(Scre
enOrientationClient* client) |
| 20 { |
| 21 return adoptPtr(new ScreenOrientationController(client)); |
| 22 } |
| 23 |
| 24 void ScreenOrientationController::addObserver(ScreenOrientation* observer) |
| 25 { |
| 26 m_observers.add(observer); |
| 27 } |
| 28 |
| 29 void ScreenOrientationController::removeObserver(ScreenOrientation* observer) |
| 30 { |
| 31 if (!m_observers.contains(observer)) |
| 32 return; |
| 33 |
| 34 m_observers.remove(observer); |
| 35 } |
| 36 |
| 37 const char* ScreenOrientationController::supplementName() |
| 38 { |
| 39 return "ScreenOrientationController"; |
| 40 } |
| 41 |
| 42 ScreenOrientationClient* ScreenOrientationController::clientFrom(Page* page) |
| 43 { |
| 44 if (ScreenOrientationController* controller = ScreenOrientationController::f
rom(page)) |
| 45 return controller->client(); |
| 46 return 0; |
| 47 } |
| 48 |
| 49 void ScreenOrientationController::orientationChanged(ScreenOrientationValue orie
ntation) |
| 50 { |
| 51 if (m_orientation == orientation) |
| 52 return; |
| 53 |
| 54 m_orientation = orientation; |
| 55 for (ObserversSet::iterator it = m_observers.begin(); it != m_observers.end(
); ++it) |
| 56 (*it)->orientationChanged(); |
| 57 } |
| 58 |
| 59 void ScreenOrientationController::setClientForTest(ScreenOrientationClient* clie
nt) |
| 60 { |
| 61 m_client = client; |
| 62 m_hasClientForTest = true; |
| 63 } |
| 64 |
| 65 void provideScreenOrientation(Page* page, ScreenOrientationClient* client) |
| 66 { |
| 67 ScreenOrientationController::provideTo(page, ScreenOrientationController::su
pplementName(), ScreenOrientationController::create(client)); |
| 68 } |
| 69 |
| 70 } // namespace WebCore |
OLD | NEW |