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

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

Issue 2391883006: Mojo-ify implementation of screen orientation locking/unlocking. (Closed)
Patch Set: Code review changes (as to PS7) Created 4 years, 1 month 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 <memory> 8 #include <memory>
9 9
10 #include "base/callback.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "content/common/content_export.h" 12 #include "content/common/content_export.h"
12 #include "content/public/browser/web_contents_observer.h" 13 #include "content/public/browser/web_contents_observer.h"
13 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h" 14 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h"
15 #include "third_party/WebKit/public/platform/modules/screen_orientation/screen_o rientation.mojom.h"
14 16
15 namespace content { 17 namespace content {
16 18
17 class ScreenOrientationDelegate; 19 class ScreenOrientationDelegate;
18 class ScreenOrientationDispatcherHost;
19 class WebContents; 20 class WebContents;
20 21
22 using LockOrientationCallback =
23 base::Callback<void(::blink::mojom::ScreenOrientationLockResult)>;
24
21 // Handles screen orientation lock/unlock. Platforms which wish to provide 25 // Handles screen orientation lock/unlock. Platforms which wish to provide
22 // custom implementations can provide a factory for ScreenOrientationDelegate. 26 // custom implementations can provide a factory for ScreenOrientationDelegate.
23 class CONTENT_EXPORT ScreenOrientationProvider : public WebContentsObserver { 27 class CONTENT_EXPORT ScreenOrientationProvider : public WebContentsObserver {
24 public: 28 public:
25 ScreenOrientationProvider(ScreenOrientationDispatcherHost* dispatcher_host, 29 ScreenOrientationProvider(WebContents* web_contents);
26 WebContents* web_contents); 30
27 ~ScreenOrientationProvider() override; 31 ~ScreenOrientationProvider() override;
28 32
29 // Lock the screen orientation to |orientations|. 33 // Lock the screen orientation to |orientation|, |callback| is the callback
30 void LockOrientation(int request_id, 34 // that should be invoked when this request receives a result.
31 blink::WebScreenOrientationLockType lock_orientation); 35 void LockOrientation(blink::WebScreenOrientationLockType orientation,
36 const LockOrientationCallback& callback);
32 37
33 // Unlock the screen orientation. 38 // Unlock the screen orientation.
34 void UnlockOrientation(); 39 void UnlockOrientation();
35 40
36 // Inform about a screen orientation update. It is called to let the provider 41 // Inform about a screen orientation update. It is called to let the provider
37 // know if a lock has been resolved. 42 // know if a lock has been resolved.
38 void OnOrientationChange(); 43 void OnOrientationChange();
39 44
40 // Provide a delegate which creates delegates for platform implementations. 45 // Provide a delegate which creates delegates for platform implementations.
41 // The delegate is not owned by ScreenOrientationProvider. 46 // The delegate is not owned by ScreenOrientationProvider.
42 static void SetDelegate(ScreenOrientationDelegate* delegate_); 47 static void SetDelegate(ScreenOrientationDelegate* delegate_);
43 48
44 // WebContentsObserver 49 // WebContentsObserver
45 void DidToggleFullscreenModeForTab(bool entered_fullscreen, 50 void DidToggleFullscreenModeForTab(bool entered_fullscreen,
46 bool will_cause_resize) override; 51 bool will_cause_resize) override;
47 52
48 private: 53 private:
49 struct LockInformation { 54 // Calls on |on_result_callback_| with |result|, followed by resetting
50 LockInformation(int request_id, blink::WebScreenOrientationLockType lock); 55 // |on_result_callback_| and |pending_lock_orientation_|.
51 int request_id; 56 void NotifyLockResult(::blink::mojom::ScreenOrientationLockResult result);
52 blink::WebScreenOrientationLockType lock;
53 };
54 57
55 // Returns the lock type that should be associated with 'natural' lock. 58 // Returns the lock type that should be associated with 'natural' lock.
56 // Returns WebScreenOrientationLockDefault if the natural lock type can't be 59 // Returns WebScreenOrientationLockDefault if the natural lock type can't be
57 // found. 60 // found.
58 blink::WebScreenOrientationLockType GetNaturalLockType() const; 61 blink::WebScreenOrientationLockType GetNaturalLockType() const;
59 62
60 // Whether the passed |lock| matches the current orientation. In other words, 63 // Whether the passed |lock| matches the current orientation. In other words,
61 // whether the orientation will need to change to match the |lock|. 64 // whether the orientation will need to change to match the |lock|.
62 bool LockMatchesCurrentOrientation(blink::WebScreenOrientationLockType lock); 65 bool LockMatchesCurrentOrientation(blink::WebScreenOrientationLockType lock);
63 66
64 // Not owned, responsible for platform implementations. 67 // Not owned, responsible for platform implementations.
65 static ScreenOrientationDelegate* delegate_; 68 static ScreenOrientationDelegate* delegate_;
66 69
67 // ScreenOrientationDispatcherHost owns ScreenOrientationProvider.
68 ScreenOrientationDispatcherHost* dispatcher_;
69
70 // Whether the ScreenOrientationProvider currently has a lock applied. 70 // Whether the ScreenOrientationProvider currently has a lock applied.
71 bool lock_applied_; 71 bool lock_applied_;
72 72
73 // Locks that require orientation changes are not completed until 73 // Locks that require orientation changes are not completed until
74 // OnOrientationChange. 74 // OnOrientationChange.
75 std::unique_ptr<LockInformation> pending_lock_; 75
76 blink::WebScreenOrientationLockType pending_lock_orientation_;
77
78 LockOrientationCallback on_result_callback_;
76 79
77 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationProvider); 80 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationProvider);
78 }; 81 };
79 82
80 } // namespace content 83 } // namespace content
81 84
82 #endif // CONTENT_PUBLIC_BROWSER_SCREEN_ORIENTATION_PROVIDER_H_ 85 #endif // CONTENT_PUBLIC_BROWSER_SCREEN_ORIENTATION_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698