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

Side by Side Diff: content/browser/device_orientation/orientation.cc

Issue 10755002: Refactors DeviceOrientation to make it more extensible (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Handles null device_data in observer Created 8 years, 5 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 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/browser/device_orientation/orientation.h"
6 #include "content/common/device_orientation_messages.h"
7
8 namespace device_orientation {
9
10 DeviceData* Orientation::Clone() const {
11 Orientation* orientation = new Orientation();
12 orientation->alpha_ = alpha_;
13 orientation->beta_ = beta_;
14 orientation->gamma_ = gamma_;
15 orientation->absolute_ = absolute_;
16 orientation->can_provide_alpha_ = can_provide_alpha_;
17 orientation->can_provide_beta_ = can_provide_beta_;
18 orientation->can_provide_gamma_ = can_provide_gamma_;
19 orientation->can_provide_absolute_ = can_provide_absolute_;
20 return orientation;
21 }
22
23 bool Orientation::IsEmpty() const {
24 return !can_provide_alpha_ && !can_provide_beta_ && !can_provide_gamma_ &&
25 !can_provide_absolute_;
26 }
27
28 // Returns true if two orientations are considered different enough that
29 // observers should be notified of the new orientation.
30 bool Orientation::SignificantlyDifferentFrom(
31 const DeviceData& other_device_data) const {
32 const Orientation& other_orientation =
33 static_cast<const Orientation&>(other_device_data);
34
35 return IsElementSignificantlyDifferent(can_provide_alpha_,
36 other_orientation.can_provide_alpha(),
37 alpha_,
38 other_orientation.alpha()) ||
39 IsElementSignificantlyDifferent(can_provide_beta_,
40 other_orientation.can_provide_beta(),
41 beta_,
42 other_orientation.beta()) ||
43 IsElementSignificantlyDifferent(can_provide_gamma_,
44 other_orientation.can_provide_gamma(),
45 gamma_,
46 other_orientation.gamma()) ||
47 can_provide_absolute_ != other_orientation.can_provide_absolute() ||
48 absolute_ != other_orientation.absolute();
49 }
50
51 IPC::Message* Orientation::CreateIPCMessage(int render_view_id) const {
52 DeviceOrientationMsg_Updated_Params params;
53 params.can_provide_alpha = can_provide_alpha_;
54 params.alpha = alpha_;
55 params.can_provide_beta = can_provide_beta_;
56 params.beta = beta_;
57 params.can_provide_gamma = can_provide_gamma_;
58 params.gamma = gamma_;
59 params.can_provide_absolute = can_provide_absolute_;
60 params.absolute = absolute_;
61
62 return new DeviceOrientationMsg_Updated(render_view_id, params);
63 }
64
65 } // namespace device_orientation
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698