OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "modules/screen_orientation/ScreenOrientation.h" | 6 #include "modules/screen_orientation/ScreenOrientation.h" |
7 | 7 |
8 #include "core/frame/DOMWindow.h" | 8 #include "core/frame/DOMWindow.h" |
9 #include "core/frame/Frame.h" | 9 #include "core/frame/Frame.h" |
10 #include "core/frame/Screen.h" | 10 #include "core/frame/Screen.h" |
| 11 #include "modules/screen_orientation/ScreenOrientationController.h" |
| 12 #include "public/platform/WebScreenOrientation.h" |
11 | 13 |
12 namespace WebCore { | 14 namespace WebCore { |
13 | 15 |
| 16 struct ScreenOrientationInfo { |
| 17 const AtomicString& name; |
| 18 blink::WebScreenOrientation orientation; |
| 19 }; |
| 20 |
| 21 static ScreenOrientationInfo* orientationsMap(unsigned& length) |
| 22 { |
| 23 DEFINE_STATIC_LOCAL(const AtomicString, portraitPrimary, ("portrait-primary"
, AtomicString::ConstructFromLiteral)); |
| 24 DEFINE_STATIC_LOCAL(const AtomicString, portraitSecondary, ("portrait-second
ary", AtomicString::ConstructFromLiteral)); |
| 25 DEFINE_STATIC_LOCAL(const AtomicString, landscapePrimary, ("landscape-primar
y", AtomicString::ConstructFromLiteral)); |
| 26 DEFINE_STATIC_LOCAL(const AtomicString, landscapeSecondary, ("landscape-seco
ndary", AtomicString::ConstructFromLiteral)); |
| 27 |
| 28 static ScreenOrientationInfo orientationMap[] = { |
| 29 { portraitPrimary, blink::WebScreenOrientationPortraitPrimary }, |
| 30 { portraitSecondary, blink::WebScreenOrientationPortraitSecondary }, |
| 31 { landscapePrimary, blink::WebScreenOrientationLandscapePrimary }, |
| 32 { landscapeSecondary, blink::WebScreenOrientationLandscapeSecondary } |
| 33 }; |
| 34 length = WTF_ARRAY_LENGTH(orientationMap); |
| 35 return orientationMap; |
| 36 } |
| 37 |
| 38 static const AtomicString& orientationToString(blink::WebScreenOrientation orien
tation) |
| 39 { |
| 40 unsigned length = 0; |
| 41 ScreenOrientationInfo* orientationMap = orientationsMap(length); |
| 42 for (unsigned i = 0; i < length; ++i) { |
| 43 if (orientationMap[i].orientation == orientation) |
| 44 return orientationMap[i].name; |
| 45 } |
| 46 // We do no handle OrientationInvalid and OrientationAny but this is fine be
cause screen.orientation |
| 47 // should never return these and WebScreenOrientation does not define those
values. |
| 48 ASSERT_NOT_REACHED(); |
| 49 return nullAtom; |
| 50 } |
| 51 |
14 ScreenOrientation::ScreenOrientation(Screen* screen) | 52 ScreenOrientation::ScreenOrientation(Screen* screen) |
15 : DOMWindowProperty(screen->frame()) | 53 : DOMWindowProperty(screen->frame()) |
16 { | 54 { |
17 } | 55 } |
18 | 56 |
19 const char* ScreenOrientation::supplementName() | 57 const char* ScreenOrientation::supplementName() |
20 { | 58 { |
21 return "ScreenOrientation"; | 59 return "ScreenOrientation"; |
22 } | 60 } |
23 | 61 |
| 62 Document* ScreenOrientation::document() const |
| 63 { |
| 64 ASSERT(m_associatedDOMWindow); |
| 65 return m_associatedDOMWindow->document(); |
| 66 } |
| 67 |
24 ScreenOrientation* ScreenOrientation::from(Screen* screen) | 68 ScreenOrientation* ScreenOrientation::from(Screen* screen) |
25 { | 69 { |
26 ScreenOrientation* supplement = static_cast<ScreenOrientation*>(Supplement<S
creen>::from(screen, supplementName())); | 70 ScreenOrientation* supplement = static_cast<ScreenOrientation*>(Supplement<S
creen>::from(screen, supplementName())); |
27 if (!supplement) { | 71 if (!supplement) { |
28 ASSERT(screen); | 72 ASSERT(screen); |
29 supplement = new ScreenOrientation(screen); | 73 supplement = new ScreenOrientation(screen); |
30 provideTo(screen, supplementName(), adoptPtr(supplement)); | 74 provideTo(screen, supplementName(), adoptPtr(supplement)); |
31 } | 75 } |
32 return supplement; | 76 return supplement; |
33 } | 77 } |
34 | 78 |
35 ScreenOrientation::~ScreenOrientation() | 79 ScreenOrientation::~ScreenOrientation() |
36 { | 80 { |
37 } | 81 } |
38 | 82 |
39 Screen* ScreenOrientation::screen() const | |
40 { | |
41 Frame* frame = this->frame(); | |
42 ASSERT(frame); | |
43 DOMWindow* window = frame->domWindow(); | |
44 ASSERT(window); | |
45 return window->screen(); | |
46 } | |
47 | |
48 const AtomicString& ScreenOrientation::orientation(Screen* screen) | 83 const AtomicString& ScreenOrientation::orientation(Screen* screen) |
49 { | 84 { |
50 // FIXME: Implement. | 85 ScreenOrientation* screenOrientation = ScreenOrientation::from(screen); |
51 DEFINE_STATIC_LOCAL(const AtomicString, portraitPrimary, ("portrait-primary"
, AtomicString::ConstructFromLiteral)); | 86 ScreenOrientationController* controller = ScreenOrientationController::from(
screenOrientation->document()); |
52 return portraitPrimary; | 87 ASSERT(controller); |
| 88 return orientationToString(controller->orientation()); |
53 } | 89 } |
54 | 90 |
55 bool ScreenOrientation::lockOrientation(Screen* screen, const Vector<String>& or
ientations) | 91 bool ScreenOrientation::lockOrientation(Screen* screen, const Vector<String>& or
ientations) |
56 { | 92 { |
57 // FIXME: Implement. | 93 // FIXME: Implement. |
58 return false; | 94 return false; |
59 } | 95 } |
60 | 96 |
61 bool ScreenOrientation::lockOrientation(Screen* screen, const AtomicString& orie
ntation) | 97 bool ScreenOrientation::lockOrientation(Screen* screen, const AtomicString& orie
ntation) |
62 { | 98 { |
63 // FIXME: Implement. | 99 // FIXME: Implement. |
64 return false; | 100 return false; |
65 } | 101 } |
66 | 102 |
67 void ScreenOrientation::unlockOrientation(Screen* screen) | 103 void ScreenOrientation::unlockOrientation(Screen* screen) |
68 { | 104 { |
69 // FIXME: Implement. | 105 // FIXME: Implement. |
70 } | 106 } |
71 | 107 |
72 } // namespace WebCore | 108 } // namespace WebCore |
OLD | NEW |