Chromium Code Reviews| 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 "content/renderer/screen_orientation/screen_orientation_dispatcher.h" | |
| 6 | |
| 7 #include "content/common/screen_orientation_messages.h" | |
| 8 #include "content/public/renderer/render_thread.h" | |
| 9 #include "third_party/WebKit/public/platform/WebScreenOrientationListener.h" | |
| 10 | |
| 11 namespace content { | |
| 12 | |
| 13 ScreenOrientationDispatcher::ScreenOrientationDispatcher( | |
| 14 RenderThread* thread) | |
| 15 : listener_(NULL) { | |
| 16 thread->AddObserver(this); | |
| 17 } | |
| 18 | |
| 19 bool ScreenOrientationDispatcher::OnControlMessageReceived( | |
| 20 const IPC::Message& message) { | |
| 21 bool handled = true; | |
| 22 | |
| 23 IPC_BEGIN_MESSAGE_MAP(ScreenOrientationDispatcher, message) | |
| 24 IPC_MESSAGE_HANDLER(ScreenOrientationMsg_OrientationChange, | |
| 25 OnOrientationChange) | |
| 26 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 27 IPC_END_MESSAGE_MAP() | |
| 28 | |
| 29 return handled; | |
| 30 } | |
| 31 | |
| 32 void ScreenOrientationDispatcher::OnOrientationChange(int orientation) { | |
| 33 // TODO(mlamouri): we might want to have OrientationChangeEvent to pass us | |
| 34 // a WebScreenOrientation instead of an int so we can let the backend decide | |
| 35 // of the relation between angle and orientation name. | |
| 36 blink::WebScreenOrientation web_orientation; | |
| 37 switch(orientation) { | |
| 38 case 0: | |
| 39 web_orientation = blink::WebScreenOrientationPortraitPrimary; | |
| 40 break; | |
| 41 case 90: | |
| 42 web_orientation = blink::WebScreenOrientationLandscapePrimary; | |
| 43 break; | |
| 44 case 180: | |
| 45 web_orientation = blink::WebScreenOrientationPortraitSecondary; | |
| 46 break; | |
| 47 case -90: | |
| 48 web_orientation = blink::WebScreenOrientationLandscapeSecondary; | |
| 49 break; | |
| 50 default: | |
| 51 NOTREACHED(); | |
| 52 web_orientation = blink::WebScreenOrientationPortraitPrimary; | |
| 53 break; | |
| 54 } | |
| 55 | |
| 56 listener_->didChangeScreenOrientation(web_orientation); | |
|
jochen (gone - plz use gerrit)
2014/02/20 16:11:04
what if listener_ is NULL?
mlamouri (slow - plz ping)
2014/02/20 16:32:47
Hmm. I was assuming that could not happen and DCHE
| |
| 57 } | |
| 58 | |
| 59 void ScreenOrientationDispatcher::setListener( | |
| 60 blink::WebScreenOrientationListener* listener) { | |
| 61 listener_ = listener; | |
| 62 } | |
| 63 | |
| 64 } // namespace content | |
| OLD | NEW |