| OLD | NEW | 
| (Empty) |  | 
 |    1 // Copyright (c) 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 #include "content/renderer/screen_orientation/mock_screen_orientation_controller
     .h" | 
 |    6  | 
 |    7 #include "base/logging.h" | 
 |    8 #include "third_party/WebKit/public/platform/WebScreenOrientationListener.h" | 
 |    9  | 
 |   10 namespace content { | 
 |   11  | 
 |   12 MockScreenOrientationController::MockScreenOrientationController() | 
 |   13     : current_lock_(blink::WebScreenOrientationLockDefault), | 
 |   14       device_orientation_(blink::WebScreenOrientationPortraitPrimary), | 
 |   15       current_orientation_(blink::WebScreenOrientationPortraitPrimary), | 
 |   16       listener_(NULL) { | 
 |   17 } | 
 |   18  | 
 |   19 void MockScreenOrientationController::SetListener( | 
 |   20     blink::WebScreenOrientationListener* listener) { | 
 |   21   listener_ = listener; | 
 |   22 } | 
 |   23  | 
 |   24 void MockScreenOrientationController::ResetData() { | 
 |   25   current_lock_ = blink::WebScreenOrientationLockDefault; | 
 |   26   device_orientation_ = blink::WebScreenOrientationPortraitPrimary; | 
 |   27   current_orientation_ = blink::WebScreenOrientationPortraitPrimary; | 
 |   28 } | 
 |   29  | 
 |   30 void MockScreenOrientationController::UpdateLock( | 
 |   31     blink::WebScreenOrientationLockType lock) { | 
 |   32   DCHECK(lock != blink::WebScreenOrientationLockDefault); | 
 |   33   current_lock_ = lock; | 
 |   34   if (IsOrientationAllowedByCurrentLock(current_orientation_)) | 
 |   35     UpdateScreenOrientation(SuitableOrientationForCurrentLock()); | 
 |   36 } | 
 |   37  | 
 |   38 void MockScreenOrientationController::ResetLock() { | 
 |   39   bool will_screen_orientation_need_updating = | 
 |   40       !IsOrientationAllowedByCurrentLock(device_orientation_); | 
 |   41   current_lock_ = blink::WebScreenOrientationLockDefault; | 
 |   42   if (will_screen_orientation_need_updating) | 
 |   43     UpdateScreenOrientation(device_orientation_); | 
 |   44 } | 
 |   45  | 
 |   46 void MockScreenOrientationController::UpdateDeviceOrientation( | 
 |   47     blink::WebScreenOrientationType orientation) { | 
 |   48   if (device_orientation_ == orientation) | 
 |   49     return; | 
 |   50   device_orientation_ = orientation; | 
 |   51   if (!IsOrientationAllowedByCurrentLock(orientation)) | 
 |   52     return; | 
 |   53   UpdateScreenOrientation(orientation); | 
 |   54 } | 
 |   55  | 
 |   56 void MockScreenOrientationController::UpdateScreenOrientation( | 
 |   57     blink::WebScreenOrientationType orientation) { | 
 |   58   if (current_orientation_ == orientation) | 
 |   59     return; | 
 |   60   current_orientation_ = orientation; | 
 |   61   if (listener_) | 
 |   62     listener_->didChangeScreenOrientation(current_orientation_); | 
 |   63 } | 
 |   64  | 
 |   65 bool MockScreenOrientationController::IsOrientationAllowedByCurrentLock( | 
 |   66     blink::WebScreenOrientationType orientation) { | 
 |   67   if (current_lock_ == blink::WebScreenOrientationLockDefault || | 
 |   68       current_lock_ == blink::WebScreenOrientationLockAny) { | 
 |   69     return true; | 
 |   70   } | 
 |   71  | 
 |   72   switch (orientation) { | 
 |   73     case blink::WebScreenOrientationPortraitPrimary: | 
 |   74       return current_lock_ == blink::WebScreenOrientationLockPortraitPrimary || | 
 |   75              current_lock_ == blink::WebScreenOrientationLockPortrait; | 
 |   76     case blink::WebScreenOrientationPortraitSecondary: | 
 |   77       return current_lock_ == | 
 |   78                  blink::WebScreenOrientationLockPortraitSecondary || | 
 |   79              current_lock_ == blink::WebScreenOrientationLockPortrait; | 
 |   80     case blink::WebScreenOrientationLandscapePrimary: | 
 |   81       return current_lock_ == blink::WebScreenOrientationLockLandscapePrimary || | 
 |   82              current_lock_ == blink::WebScreenOrientationLockLandscape; | 
 |   83     case blink::WebScreenOrientationLandscapeSecondary: | 
 |   84       return current_lock_ == | 
 |   85                  blink::WebScreenOrientationLockLandscapeSecondary || | 
 |   86              current_lock_ == blink::WebScreenOrientationLockLandscape; | 
 |   87     default: | 
 |   88       return false; | 
 |   89   } | 
 |   90 } | 
 |   91  | 
 |   92 blink::WebScreenOrientationType | 
 |   93 MockScreenOrientationController::SuitableOrientationForCurrentLock() { | 
 |   94   switch (current_lock_) { | 
 |   95     case blink::WebScreenOrientationLockPortraitSecondary: | 
 |   96       return blink::WebScreenOrientationPortraitSecondary; | 
 |   97     case blink::WebScreenOrientationLockLandscapePrimary: | 
 |   98     case blink::WebScreenOrientationLockLandscape: | 
 |   99       return blink::WebScreenOrientationLandscapePrimary; | 
 |  100     case blink::WebScreenOrientationLockLandscapeSecondary: | 
 |  101       return blink::WebScreenOrientationLandscapePrimary; | 
 |  102     default: | 
 |  103       return blink::WebScreenOrientationPortraitPrimary; | 
 |  104   } | 
 |  105 } | 
 |  106  | 
 |  107 } // namespace content | 
| OLD | NEW |