forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reland ScreenOrientationDelegate on ChromeOS
This change fixes the error in: https://codereview.chromium.org/648733003 This reverts commit 61aaa96. TBR=avi@chromium.org, oshima@chromium.org, rbyers@chromium.org, mlamouri@chromium.org BUG=396760 Review URL: https://codereview.chromium.org/723633003 Cr-Commit-Position: refs/heads/master@{#303952}
- Loading branch information
jonross
authored and
Commit bot
committed
Nov 13, 2014
1 parent
858fd17
commit f21fea1
Showing
13 changed files
with
487 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
include_rules = [ | ||
"+content/public/browser/screen_orientation_delegate.h", | ||
"+content/public/browser/screen_orientation_provider.h", | ||
"+content/public/browser/browser_context.h", | ||
"+content/public/browser/web_contents.h", | ||
"+third_party/WebKit/public/platform/WebScreenOrientationLockType.h", | ||
] | ||
|
||
specific_include_rules = { | ||
".*test\.cc": [ | ||
"+content/public/test/test_browser_context.h" | ||
], | ||
} |
180 changes: 180 additions & 0 deletions
180
ash/content/display/screen_orientation_delegate_chromeos.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ash/content/display/screen_orientation_delegate_chromeos.h" | ||
|
||
#include "ash/ash_switches.h" | ||
#include "ash/display/display_info.h" | ||
#include "ash/display/display_manager.h" | ||
#include "ash/shell.h" | ||
#include "ash/wm/maximize_mode/maximize_mode_controller.h" | ||
#include "base/command_line.h" | ||
#include "content/public/browser/screen_orientation_provider.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "ui/aura/window.h" | ||
#include "ui/gfx/display.h" | ||
#include "ui/gfx/geometry/size.h" | ||
|
||
namespace { | ||
|
||
blink::WebScreenOrientationLockType GetDisplayNaturalOrientation() { | ||
ash::DisplayManager* display_manager = | ||
ash::Shell::GetInstance()->display_manager(); | ||
if (!display_manager->HasInternalDisplay()) | ||
return blink::WebScreenOrientationLockLandscape; | ||
|
||
ash::DisplayInfo info = | ||
display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()); | ||
gfx::Size size = info.size_in_pixel(); | ||
switch (info.rotation()) { | ||
case gfx::Display::ROTATE_0: | ||
case gfx::Display::ROTATE_180: | ||
return size.height() >= size.width() | ||
? blink::WebScreenOrientationLockPortrait | ||
: blink::WebScreenOrientationLockLandscape; | ||
case gfx::Display::ROTATE_90: | ||
case gfx::Display::ROTATE_270: | ||
return size.height() < size.width() | ||
? blink::WebScreenOrientationLockPortrait | ||
: blink::WebScreenOrientationLockLandscape; | ||
} | ||
NOTREACHED(); | ||
return blink::WebScreenOrientationLockLandscape; | ||
} | ||
|
||
} // namespace | ||
|
||
namespace ash { | ||
|
||
ScreenOrientationDelegate::ScreenOrientationDelegate() | ||
: locking_window_(NULL), | ||
natural_orientation_(GetDisplayNaturalOrientation()) { | ||
content::ScreenOrientationProvider::SetDelegate(this); | ||
} | ||
|
||
ScreenOrientationDelegate::~ScreenOrientationDelegate() { | ||
content::ScreenOrientationProvider::SetDelegate(NULL); | ||
} | ||
|
||
bool ScreenOrientationDelegate::FullScreenRequired( | ||
content::WebContents* web_contents) { | ||
return true; | ||
} | ||
|
||
void ScreenOrientationDelegate::Lock( | ||
content::WebContents* web_contents, | ||
blink::WebScreenOrientationLockType lock_orientation) { | ||
aura::Window* requesting_window = web_contents->GetNativeView(); | ||
|
||
// TODO(jonross): Make ScreenOrientationDelegate responsible for rotation | ||
// lock. Have MaximizeModeController, and TrayRotationLock both use it | ||
// instead. | ||
MaximizeModeController* controller = | ||
Shell::GetInstance()->maximize_mode_controller(); | ||
|
||
// TODO(jonross): Track one rotation lock per window. When the active window | ||
// changes apply any corresponding rotation lock. | ||
if (!locking_window_) | ||
locking_window_ = requesting_window; | ||
else if (requesting_window != locking_window_) | ||
return; | ||
|
||
switch (lock_orientation) { | ||
case blink::WebScreenOrientationLockAny: | ||
controller->SetRotationLocked(false); | ||
locking_window_ = NULL; | ||
break; | ||
case blink::WebScreenOrientationLockDefault: | ||
NOTREACHED(); | ||
break; | ||
case blink::WebScreenOrientationLockPortraitPrimary: | ||
LockRotationToPrimaryOrientation(blink::WebScreenOrientationLockPortrait); | ||
break; | ||
case blink::WebScreenOrientationLockLandscape: | ||
case blink::WebScreenOrientationLockPortrait: | ||
LockToRotationMatchingOrientation(lock_orientation); | ||
break; | ||
case blink::WebScreenOrientationLockPortraitSecondary: | ||
LockRotationToSecondaryOrientation( | ||
blink::WebScreenOrientationLockPortrait); | ||
break; | ||
case blink::WebScreenOrientationLockLandscapeSecondary: | ||
LockRotationToSecondaryOrientation( | ||
blink::WebScreenOrientationLockLandscape); | ||
break; | ||
case blink::WebScreenOrientationLockLandscapePrimary: | ||
LockRotationToPrimaryOrientation( | ||
blink::WebScreenOrientationLockLandscape); | ||
break; | ||
case blink::WebScreenOrientationLockNatural: | ||
controller->LockRotation(gfx::Display::ROTATE_0); | ||
break; | ||
default: | ||
NOTREACHED(); | ||
break; | ||
} | ||
} | ||
|
||
bool ScreenOrientationDelegate::ScreenOrientationProviderSupported() { | ||
return Shell::GetInstance() | ||
->maximize_mode_controller() | ||
->IsMaximizeModeWindowManagerEnabled() && | ||
CommandLine::ForCurrentProcess()->HasSwitch( | ||
switches::kAshEnableTouchViewTesting); | ||
} | ||
|
||
void ScreenOrientationDelegate::Unlock(content::WebContents* web_contents) { | ||
aura::Window* requesting_window = web_contents->GetNativeView(); | ||
if (requesting_window != locking_window_) | ||
return; | ||
locking_window_ = NULL; | ||
Shell::GetInstance()->maximize_mode_controller()->SetRotationLocked(false); | ||
} | ||
|
||
void ScreenOrientationDelegate::LockRotationToPrimaryOrientation( | ||
blink::WebScreenOrientationLockType lock_orientation) { | ||
Shell::GetInstance()->maximize_mode_controller()->LockRotation( | ||
natural_orientation_ == lock_orientation ? gfx::Display::ROTATE_0 | ||
: gfx::Display::ROTATE_90); | ||
} | ||
|
||
void ScreenOrientationDelegate::LockRotationToSecondaryOrientation( | ||
blink::WebScreenOrientationLockType lock_orientation) { | ||
Shell::GetInstance()->maximize_mode_controller()->LockRotation( | ||
natural_orientation_ == lock_orientation ? gfx::Display::ROTATE_180 | ||
: gfx::Display::ROTATE_270); | ||
} | ||
|
||
void ScreenOrientationDelegate::LockToRotationMatchingOrientation( | ||
blink::WebScreenOrientationLockType lock_orientation) { | ||
// TODO(jonross): Update MaximizeModeController to allow rotation between | ||
// two angles of an orientation (e.g. from ROTATE_0 to ROTATE_180, and from | ||
// ROTATE_90 to ROTATE_270) | ||
DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | ||
if (!display_manager->HasInternalDisplay()) | ||
return; | ||
|
||
gfx::Display::Rotation rotation = | ||
display_manager->GetDisplayInfo(gfx::Display::InternalDisplayId()) | ||
.rotation(); | ||
MaximizeModeController* controller = | ||
Shell::GetInstance()->maximize_mode_controller(); | ||
if (natural_orientation_ == lock_orientation) { | ||
if (rotation == gfx::Display::ROTATE_0 || | ||
rotation == gfx::Display::ROTATE_180) { | ||
controller->SetRotationLocked(true); | ||
} else { | ||
controller->LockRotation(gfx::Display::ROTATE_0); | ||
} | ||
} else { | ||
if (rotation == gfx::Display::ROTATE_90 || | ||
rotation == gfx::Display::ROTATE_270) { | ||
controller->SetRotationLocked(true); | ||
} else { | ||
controller->LockRotation(gfx::Display::ROTATE_90); | ||
} | ||
} | ||
} | ||
|
||
} // namespace ash |
64 changes: 64 additions & 0 deletions
64
ash/content/display/screen_orientation_delegate_chromeos.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_DELEGATE_CHROMEOS_H_ | ||
#define ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_DELEGATE_CHROMEOS_H_ | ||
|
||
#include "base/macros.h" | ||
#include "content/public/browser/screen_orientation_delegate.h" | ||
#include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h" | ||
|
||
namespace aura { | ||
class Window; | ||
} | ||
|
||
namespace content { | ||
class WebContents; | ||
} | ||
|
||
namespace ash { | ||
|
||
// Implements ChromeOS specific functionality for ScreenOrientationProvider. | ||
class ScreenOrientationDelegate : public content::ScreenOrientationDelegate { | ||
public: | ||
ScreenOrientationDelegate(); | ||
virtual ~ScreenOrientationDelegate(); | ||
|
||
// content::ScreenOrientationDelegate: | ||
bool FullScreenRequired(content::WebContents* web_contents) override; | ||
void Lock(content::WebContents* web_contents, | ||
blink::WebScreenOrientationLockType lock_orientation) override; | ||
bool ScreenOrientationProviderSupported() override; | ||
void Unlock(content::WebContents* web_contents) override; | ||
|
||
private: | ||
// Locks rotation to the angle matching the primary orientation for | ||
// |lock_orientation|. | ||
void LockRotationToPrimaryOrientation( | ||
blink::WebScreenOrientationLockType lock_orientation); | ||
|
||
// Locks rotation to the angle matching the secondary orientation for | ||
// |lock_orientation|. | ||
void LockRotationToSecondaryOrientation( | ||
blink::WebScreenOrientationLockType lock_orientation); | ||
|
||
// For orientations that do not specify primary or secondary, locks to the | ||
// current rotation if it matches |lock_orientation|. Otherwise locks to a | ||
// matching rotation. | ||
void LockToRotationMatchingOrientation( | ||
blink::WebScreenOrientationLockType lock_orientation); | ||
|
||
// The window that has applied the current lock. No other window can apply a | ||
// lock until the current window unlocks rotation. | ||
aura::Window* locking_window_; | ||
|
||
// The orientation of the display when at a rotation of 0. | ||
blink::WebScreenOrientationLockType natural_orientation_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(ScreenOrientationDelegate); | ||
}; | ||
|
||
} // namespace ash | ||
|
||
#endif // ASH_CONTENT_DISPLAY_SCREEN_ORIENTATION_DELEGATE_CHROMEOS_H_ |
Oops, something went wrong.