Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/compiler_specific.h" | |
| 9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 10 #include "base/optional.h" | 11 #include "base/optional.h" |
| 11 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 13 #include "content/public/browser/web_contents_binding_set.h" | |
| 12 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
| 15 #include "device/screen_orientation/public/interfaces/screen_orientation.mojom.h " | |
| 13 #include "device/screen_orientation/public/interfaces/screen_orientation_lock_ty pes.mojom.h" | 16 #include "device/screen_orientation/public/interfaces/screen_orientation_lock_ty pes.mojom.h" |
| 14 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h" | 17 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h" |
| 15 | 18 |
| 16 namespace content { | 19 namespace content { |
| 17 | 20 |
| 18 class ScreenOrientationDelegate; | 21 class ScreenOrientationDelegate; |
| 19 class WebContents; | 22 class WebContents; |
| 20 | 23 |
| 21 using LockOrientationCallback = | |
| 22 base::Callback<void(device::mojom::ScreenOrientationLockResult)>; | |
| 23 | |
| 24 // Handles screen orientation lock/unlock. Platforms which wish to provide | 24 // Handles screen orientation lock/unlock. Platforms which wish to provide |
| 25 // custom implementations can provide a factory for ScreenOrientationDelegate. | 25 // custom implementations can provide a factory for ScreenOrientationDelegate. |
| 26 class CONTENT_EXPORT ScreenOrientationProvider : public WebContentsObserver { | 26 class CONTENT_EXPORT ScreenOrientationProvider |
| 27 : NON_EXPORTED_BASE(public device::mojom::ScreenOrientation), | |
| 28 public WebContentsObserver { | |
| 27 public: | 29 public: |
| 28 ScreenOrientationProvider(WebContents* web_contents); | 30 ScreenOrientationProvider(WebContents* web_contents); |
| 29 | 31 |
| 30 ~ScreenOrientationProvider() override; | 32 ~ScreenOrientationProvider() override; |
| 31 | 33 |
| 32 // Lock the screen orientation to |orientation|, |callback| is the callback | 34 // device::mojom::ScreenOrientation: |
| 33 // that should be invoked when this request receives a result. | |
| 34 void LockOrientation(blink::WebScreenOrientationLockType orientation, | 35 void LockOrientation(blink::WebScreenOrientationLockType orientation, |
| 35 const LockOrientationCallback& callback); | 36 const LockOrientationCallback& callback) override; |
| 36 | 37 void UnlockOrientation() override; |
| 37 // Unlock the screen orientation. | |
| 38 void UnlockOrientation(); | |
| 39 | 38 |
| 40 // Inform about a screen orientation update. It is called to let the provider | 39 // Inform about a screen orientation update. It is called to let the provider |
| 41 // know if a lock has been resolved. | 40 // know if a lock has been resolved. |
| 42 void OnOrientationChange(); | 41 void OnOrientationChange(); |
| 43 | 42 |
| 44 // Provide a delegate which creates delegates for platform implementations. | 43 // Provide a delegate which creates delegates for platform implementations. |
| 45 // The delegate is not owned by ScreenOrientationProvider. | 44 // The delegate is not owned by ScreenOrientationProvider. |
| 46 static void SetDelegate(ScreenOrientationDelegate* delegate_); | 45 static void SetDelegate(ScreenOrientationDelegate* delegate_); |
|
leonhsl(Using Gerrit)
2017/01/23 10:11:10
I'm not sure whether we should move all implementa
blundell
2017/01/24 09:58:24
I'm tempted to completely hide ScreenOrientationPr
| |
| 47 | 46 |
| 48 // WebContentsObserver | 47 // WebContentsObserver |
| 49 void DidToggleFullscreenModeForTab(bool entered_fullscreen, | 48 void DidToggleFullscreenModeForTab(bool entered_fullscreen, |
| 50 bool will_cause_resize) override; | 49 bool will_cause_resize) override; |
| 50 void DidNavigateMainFrame(const LoadCommittedDetails& details, | |
| 51 const FrameNavigateParams& params) override; | |
| 51 | 52 |
| 52 private: | 53 private: |
| 53 // Calls on |on_result_callback_| with |result|, followed by resetting | 54 // Calls on |on_result_callback_| with |result|, followed by resetting |
| 54 // |on_result_callback_| and |pending_lock_orientation_|. | 55 // |on_result_callback_| and |pending_lock_orientation_|. |
| 55 void NotifyLockResult(device::mojom::ScreenOrientationLockResult result); | 56 void NotifyLockResult(device::mojom::ScreenOrientationLockResult result); |
| 56 | 57 |
| 57 // Returns the lock type that should be associated with 'natural' lock. | 58 // Returns the lock type that should be associated with 'natural' lock. |
| 58 // Returns WebScreenOrientationLockDefault if the natural lock type can't be | 59 // Returns WebScreenOrientationLockDefault if the natural lock type can't be |
| 59 // found. | 60 // found. |
| 60 blink::WebScreenOrientationLockType GetNaturalLockType() const; | 61 blink::WebScreenOrientationLockType GetNaturalLockType() const; |
| 61 | 62 |
| 62 // Whether the passed |lock| matches the current orientation. In other words, | 63 // Whether the passed |lock| matches the current orientation. In other words, |
| 63 // whether the orientation will need to change to match the |lock|. | 64 // whether the orientation will need to change to match the |lock|. |
| 64 bool LockMatchesCurrentOrientation(blink::WebScreenOrientationLockType lock); | 65 bool LockMatchesCurrentOrientation(blink::WebScreenOrientationLockType lock); |
| 65 | 66 |
| 66 // Not owned, responsible for platform implementations. | 67 // Not owned, responsible for platform implementations. |
| 67 static ScreenOrientationDelegate* delegate_; | 68 static ScreenOrientationDelegate* delegate_; |
| 68 | 69 |
| 69 // Whether the ScreenOrientationProvider currently has a lock applied. | 70 // Whether the ScreenOrientationProvider currently has a lock applied. |
| 70 bool lock_applied_; | 71 bool lock_applied_; |
| 71 | 72 |
| 72 // Locks that require orientation changes are not completed until | 73 // Lock that require orientation changes are not completed until |
| 73 // OnOrientationChange. | 74 // OnOrientationChange. |
| 74 base::Optional<blink::WebScreenOrientationLockType> pending_lock_orientation_; | 75 base::Optional<blink::WebScreenOrientationLockType> pending_lock_orientation_; |
| 75 | 76 |
| 76 LockOrientationCallback pending_callback_; | 77 LockOrientationCallback pending_callback_; |
| 77 | 78 |
| 79 WebContentsFrameBindingSet<device::mojom::ScreenOrientation> bindings_; | |
| 80 | |
| 78 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationProvider); | 81 DISALLOW_COPY_AND_ASSIGN(ScreenOrientationProvider); |
| 79 }; | 82 }; |
| 80 | 83 |
| 81 } // namespace content | 84 } // namespace content |
| 82 | 85 |
| 83 #endif // CONTENT_PUBLIC_BROWSER_SCREEN_ORIENTATION_PROVIDER_H_ | 86 #endif // CONTENT_PUBLIC_BROWSER_SCREEN_ORIENTATION_PROVIDER_H_ |
| OLD | NEW |