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

Side by Side Diff: chrome/renderer/device_orientation_dispatcher.cc

Issue 6151011: Introduce RenderView::Observer interface so that RenderView doesn't have to k... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/renderer/device_orientation_dispatcher.h" 5 #include "chrome/renderer/device_orientation_dispatcher.h"
6 6
7 #include "chrome/common/render_messages_params.h" 7 #include "chrome/common/render_messages_params.h"
8 #include "chrome/renderer/render_view.h"
9 #include "third_party/WebKit/WebKit/chromium/public/WebDeviceOrientation.h" 8 #include "third_party/WebKit/WebKit/chromium/public/WebDeviceOrientation.h"
10 #include "third_party/WebKit/WebKit/chromium/public/WebDeviceOrientationControll er.h" 9 #include "third_party/WebKit/WebKit/chromium/public/WebDeviceOrientationControll er.h"
11 10
12 DeviceOrientationDispatcher::DeviceOrientationDispatcher( 11 DeviceOrientationDispatcher::DeviceOrientationDispatcher(
13 RenderView* render_view) 12 RenderView* render_view)
14 : render_view_(render_view), 13 : RenderView::Observer(render_view),
15 controller_(NULL), 14 controller_(NULL),
16 started_(false) { 15 started_(false) {
17 } 16 }
18 17
19 DeviceOrientationDispatcher::~DeviceOrientationDispatcher() { 18 DeviceOrientationDispatcher::~DeviceOrientationDispatcher() {
20 if (started_) 19 if (started_)
21 stopUpdating(); 20 stopUpdating();
22 } 21 }
23 22
24 bool DeviceOrientationDispatcher::OnMessageReceived(const IPC::Message& msg) { 23 bool DeviceOrientationDispatcher::OnMessageReceived(const IPC::Message& msg) {
25 bool handled = true; 24 bool handled = true;
26 IPC_BEGIN_MESSAGE_MAP(DeviceOrientationDispatcher, msg) 25 IPC_BEGIN_MESSAGE_MAP(DeviceOrientationDispatcher, msg)
27 IPC_MESSAGE_HANDLER(ViewMsg_DeviceOrientationUpdated, 26 IPC_MESSAGE_HANDLER(ViewMsg_DeviceOrientationUpdated,
28 OnDeviceOrientationUpdated) 27 OnDeviceOrientationUpdated)
29 IPC_MESSAGE_UNHANDLED(handled = false) 28 IPC_MESSAGE_UNHANDLED(handled = false)
30 IPC_END_MESSAGE_MAP() 29 IPC_END_MESSAGE_MAP()
31 return handled; 30 return handled;
32 } 31 }
33 32
34 void DeviceOrientationDispatcher::setController( 33 void DeviceOrientationDispatcher::setController(
35 WebKit::WebDeviceOrientationController* controller) { 34 WebKit::WebDeviceOrientationController* controller) {
36 controller_.reset(controller); 35 controller_.reset(controller);
37 } 36 }
38 37
39 void DeviceOrientationDispatcher::startUpdating() { 38 void DeviceOrientationDispatcher::startUpdating() {
40 render_view_->Send(new ViewHostMsg_DeviceOrientation_StartUpdating( 39 Send(new ViewHostMsg_DeviceOrientation_StartUpdating(routing_id()));
41 render_view_->routing_id()));
42 started_ = true; 40 started_ = true;
43 } 41 }
44 42
45 void DeviceOrientationDispatcher::stopUpdating() { 43 void DeviceOrientationDispatcher::stopUpdating() {
46 render_view_->Send(new ViewHostMsg_DeviceOrientation_StopUpdating( 44 Send(new ViewHostMsg_DeviceOrientation_StopUpdating(routing_id()));
47 render_view_->routing_id()));
48 started_ = false; 45 started_ = false;
49 } 46 }
50 47
51 WebKit::WebDeviceOrientation DeviceOrientationDispatcher::lastOrientation() 48 WebKit::WebDeviceOrientation DeviceOrientationDispatcher::lastOrientation()
52 const { 49 const {
53 if (!last_orientation_.get()) 50 if (!last_orientation_.get())
54 return WebKit::WebDeviceOrientation::nullOrientation(); 51 return WebKit::WebDeviceOrientation::nullOrientation();
55 52
56 return *last_orientation_; 53 return *last_orientation_;
57 } 54 }
(...skipping 26 matching lines...) Expand all
84 81
85 last_orientation_.reset(new WebKit::WebDeviceOrientation(p.can_provide_alpha, 82 last_orientation_.reset(new WebKit::WebDeviceOrientation(p.can_provide_alpha,
86 p.alpha, 83 p.alpha,
87 p.can_provide_beta, 84 p.can_provide_beta,
88 p.beta, 85 p.beta,
89 p.can_provide_gamma, 86 p.can_provide_gamma,
90 p.gamma)); 87 p.gamma));
91 88
92 controller_->didChangeDeviceOrientation(*last_orientation_); 89 controller_->didChangeDeviceOrientation(*last_orientation_);
93 } 90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698