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