Add NO_ORIENTATION_PREFERENCE type to unset the preferred orientation 39/219639/10
authorWonsik Jung <sidein@samsung.com>
Sun, 8 Dec 2019 19:51:14 +0000 (04:51 +0900)
committerWonsik Jung <sidein@samsung.com>
Wed, 18 Dec 2019 08:30:47 +0000 (17:30 +0900)
For unseting the preferred orientation for window, NO_ORIENTATION_PREFERENCE type is added to WindowOrientation enum.
To unset the preferred orientation, SetPreferredOrienation() should be called with NO_ORIENTATION_PREFERENCE.

Change-Id: Ia2de67d6533cef59b58340fca51286239c1a297d

dali/internal/window-system/common/window-impl.cpp
dali/internal/window-system/common/window-impl.h
dali/public-api/adaptor-framework/window.h

index 1e9e79b..3001f7a 100644 (file)
@@ -74,7 +74,7 @@ Window::Window()
   mResizeEnabled( false ),
   mType( Dali::Window::NORMAL ),
   mParentWindow( NULL ),
-  mPreferredAngle( 0 ),
+  mPreferredAngle( Dali::Window::NO_ORIENTATION_PREFERENCE ),
   mRotationAngle( 0 ),
   mWindowWidth( 0 ),
   mWindowHeight( 0 ),
@@ -211,29 +211,36 @@ Dali::RenderTaskList Window::GetRenderTaskList() const
 
 void Window::AddAvailableOrientation( Dali::Window::WindowOrientation orientation )
 {
+  if( IsOrientationAvailable( orientation ) == false )
+  {
+    return;
+  }
+
   bool found = false;
-  if( orientation <= Dali::Window::LANDSCAPE_INVERSE )
+  int convertedAngle = ConvertToAngle( orientation );
+  for( std::size_t i = 0; i < mAvailableAngles.size(); i++ )
   {
-    int convertedAngle = ConvertToAngle( orientation );
-    for( std::size_t i = 0; i < mAvailableAngles.size(); i++ )
+    if( mAvailableAngles[i] == convertedAngle )
     {
-      if( mAvailableAngles[i] == convertedAngle )
-      {
-        found = true;
-        break;
-      }
+      found = true;
+      break;
     }
+  }
 
-    if( !found )
-    {
-      mAvailableAngles.push_back( convertedAngle );
-      SetAvailableAnlges( mAvailableAngles );
-    }
+  if( !found )
+  {
+    mAvailableAngles.push_back( convertedAngle );
+    SetAvailableAnlges( mAvailableAngles );
   }
 }
 
 void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orientation )
 {
+  if( IsOrientationAvailable( orientation ) == false )
+  {
+    return;
+  }
+
   int convertedAngle = ConvertToAngle( orientation );
   for( std::vector< int >::iterator iter = mAvailableAngles.begin();
        iter != mAvailableAngles.end(); ++iter )
@@ -250,6 +257,10 @@ void Window::RemoveAvailableOrientation( Dali::Window::WindowOrientation orienta
 
 void Window::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
 {
+  if( orientation < Dali::Window::NO_ORIENTATION_PREFERENCE || orientation > Dali::Window::LANDSCAPE_INVERSE )
+  {
+    return;
+  }
   mPreferredAngle = ConvertToAngle( orientation );
   mWindowBase->SetPreferredAngle( mPreferredAngle );
 }
@@ -298,6 +309,11 @@ int Window::ConvertToAngle( Dali::Window::WindowOrientation orientation )
         convertAngle = 270;
         break;
       }
+      case Dali::Window::NO_ORIENTATION_PREFERENCE:
+      {
+        convertAngle = -1;
+        break;
+      }
     }
   }
   return convertAngle;
@@ -330,11 +346,26 @@ Dali::Window::WindowOrientation Window::ConvertToOrientation( int angle )
         orientation = Dali::Window::PORTRAIT_INVERSE;
         break;
       }
+      case -1:
+      {
+        orientation = Dali::Window::NO_ORIENTATION_PREFERENCE;
+        break;
+      }
     }
   }
   return orientation;
 }
 
+bool Window::IsOrientationAvailable( Dali::Window::WindowOrientation orientation ) const
+{
+  if( orientation <= Dali::Window::NO_ORIENTATION_PREFERENCE || orientation > Dali::Window::LANDSCAPE_INVERSE )
+  {
+    DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation );
+    return false;
+  }
+  return true;
+}
+
 Dali::Any Window::GetNativeHandle() const
 {
   return mWindowSurface->GetNativeWindow();
index 229d091..d630238 100644 (file)
@@ -419,6 +419,11 @@ private:
    */
   Dali::Window::WindowOrientation ConvertToOrientation( int angle );
 
+  /**
+   * @brief Check available window orientation for Available orientation.
+   */
+  bool IsOrientationAvailable( Dali::Window::WindowOrientation orientation ) const;
+
 private: // Dali::Internal::Adaptor::SceneHolder
 
   /**
index fe28f45..f60cd58 100755 (executable)
@@ -78,6 +78,11 @@ public:
 
   /**
    * @brief Enumeration for orientation of the window is the way in which a rectangular page is oriented for normal viewing.
+   *
+   * This Enumeration is used the available orientation APIs and the preferred orientation.
+   *
+   * Especially, NO_ORIENTATION_PREFERENCE only has the effect for the preferred orientation.
+   * It is used to unset the preferred orientation with SetPreferredOrientation.
    * @SINCE_1_0.0
    */
   enum WindowOrientation
@@ -85,7 +90,8 @@ public:
     PORTRAIT = 0,  ///< Portrait orientation. The height of the display area is greater than the width. @SINCE_1_0.0
     LANDSCAPE = 90,  ///< Landscape orientation. A wide view area is needed. @SINCE_1_0.0
     PORTRAIT_INVERSE = 180,  ///< Portrait inverse orientation @SINCE_1_0.0
-    LANDSCAPE_INVERSE = 270  ///< Landscape inverse orientation @SINCE_1_0.0
+    LANDSCAPE_INVERSE = 270,  ///< Landscape inverse orientation @SINCE_1_0.0
+    NO_ORIENTATION_PREFERENCE = -1 ///< No orientation. It is for the preferred orientation.  @SINCE_1_4.51
   };
 
   /**
@@ -360,6 +366,8 @@ public:
    * @SINCE_1_0.0
    * @param[in] orientation The preferred orientation
    * @pre Orientation is in the list of available orientations.
+   *
+   * @note To unset the preferred orientation, orientation should be set NO_ORIENTATION_PREFERENCE.
    */
   void SetPreferredOrientation( WindowOrientation orientation );