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

Side by Side Diff: content/public/browser/screen_orientation_provider.h

Issue 546453004: Centralize ScreenOrientationProvider logic, add platform delegates (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@screen_orientation_public_impl_split
Patch Set: Remove Factory Created 6 years, 2 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
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 #ifndef CONTENT_PUBLIC_BROWSER_SCREEN_ORIENTATION_PROVIDER_H_ 5 #ifndef CONTENT_PUBLIC_BROWSER_SCREEN_ORIENTATION_PROVIDER_H_
6 #define CONTENT_PUBLIC_BROWSER_SCREEN_ORIENTATION_PROVIDER_H_ 6 #define CONTENT_PUBLIC_BROWSER_SCREEN_ORIENTATION_PROVIDER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
9 #include "content/common/content_export.h" 10 #include "content/common/content_export.h"
11 #include "content/public/browser/web_contents_observer.h"
10 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h" 12 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h"
11 13
12 namespace content { 14 namespace content {
13 15
16 class ScreenOrientationDelegate;
14 class ScreenOrientationDispatcherHost; 17 class ScreenOrientationDispatcherHost;
15 class WebContents; 18 class WebContents;
16 19
17 // Interface that needs to be implemented by any backend that wants to handle 20 // Handles screen orientation lock/unlock. Platforms which wish to provide
18 // screen orientation lock/unlock. 21 // custom implementations can provide a factory for ScreenOrientationDelegate.
19 class CONTENT_EXPORT ScreenOrientationProvider { 22 class CONTENT_EXPORT ScreenOrientationProvider : public WebContentsObserver {
20 public: 23 public:
24 ScreenOrientationProvider(ScreenOrientationDispatcherHost* dispatcher_host,
25 WebContents* web_contents);
26 virtual ~ScreenOrientationProvider();
27
21 // Lock the screen orientation to |orientations|. 28 // Lock the screen orientation to |orientations|.
22 virtual void LockOrientation( 29 void LockOrientation(int request_id,
23 int request_id, 30 blink::WebScreenOrientationLockType lock_orientation);
24 blink::WebScreenOrientationLockType orientations) = 0;
25 31
26 // Unlock the screen orientation. 32 // Unlock the screen orientation.
27 virtual void UnlockOrientation() = 0; 33 void UnlockOrientation();
28 34
29 // Inform about a screen orientation update. It is called to let the provider 35 // Inform about a screen orientation update. It is called to let the provider
30 // know if a lock has been resolved. 36 // know if a lock has been resolved.
31 virtual void OnOrientationChange() = 0; 37 void OnOrientationChange();
32 38
33 virtual ~ScreenOrientationProvider() {} 39 // Provide a delegate which creates delegates for platform implementations.
40 // The delegate is not owned by ScreenOrientationProvider.
41 static void SetDelegate(ScreenOrientationDelegate* delegate_);
34 42
35 protected: 43 // WebContentsObserver
36 friend class ScreenOrientationDispatcherHostImpl; 44 virtual void DidToggleFullscreenModeForTab(bool entered_fullscreen) OVERRIDE;
37 45
38 static ScreenOrientationProvider* Create( 46 private:
39 ScreenOrientationDispatcherHost* dispatcher_host, 47 struct LockInformation {
40 WebContents* web_contents); 48 LockInformation(int request_id, blink::WebScreenOrientationLockType lock);
49 int request_id;
50 blink::WebScreenOrientationLockType lock;
51 };
41 52
42 ScreenOrientationProvider() {} 53 // Returns the lock type that should be associated with 'natural' lock.
54 // Returns WebScreenOrientationLockDefault if the natural lock type can't be
55 // found.
56 blink::WebScreenOrientationLockType GetNaturalLockType() const;
57
58 // Whether the passed |lock| matches the current orientation. In other words,
59 // whether the orientation will need to change to match the |lock|.
60 bool LockMatchesCurrentOrientation(blink::WebScreenOrientationLockType lock);
61
62 // Not owned, responsible for platform implementations.
63 static ScreenOrientationDelegate* delegate_;
64
65 // ScreenOrientationDispatcherHost owns ScreenOrientationProvider.
66 ScreenOrientationDispatcherHost* dispatcher_;
67
68 // Whether the ScreenOrientationProvider currently has a lock applied.
69 bool lock_applied_;
70
71 // Locks that require orientation changes are not completed until
72 // OnOrientationChange.
73 scoped_ptr<LockInformation> pending_lock_;
43 74
44 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationProvider); 75 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationProvider);
45 }; 76 };
46 77
47 #if !defined(OS_ANDROID)
48 // static
49 ScreenOrientationProvider* ScreenOrientationProvider::Create(
50 ScreenOrientationDispatcherHost* dispatcher_host,
51 WebContents* web_contents) {
52 return NULL;
53 }
54 #endif // !defined(OS_ANDROID)
55
56 } // namespace content 78 } // namespace content
57 79
58 #endif // CONTENT_PUBLIC_BROWSER_SCREEN_ORIENTATION_PROVIDER_H_ 80 #endif // CONTENT_PUBLIC_BROWSER_SCREEN_ORIENTATION_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698