]> khamidou — GitHub mirrors - electron.git/commitdiff
Reorgnize how attributes work
authorCheng Zhao <zcbenz@gmail.com>
Sat, 23 Jan 2016 10:23:18 +0000 (02:23 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Sun, 24 Jan 2016 06:31:37 +0000 (14:31 +0800)
atom/browser/native_window.cc
atom/browser/native_window_mac.mm
atom/browser/native_window_views.cc
atom/browser/native_window_views.h
atom/browser/native_window_views_win.cc

index 4435915db0371cfe0ec9ede11925db5335fcbe49..7d0ae5a5b764fbb9311e71509f4d0204f9bb243f 100644 (file)
@@ -116,23 +116,15 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
     SetSizeConstraints(size_constraints);
   }
 #if defined(OS_WIN) || defined(USE_X11)
-  bool resizable;
-  if (options.Get(options::kResizable, &resizable)) {
-    SetResizable(resizable);
-  }
-  bool minimizable;
-  if (options.Get(options::kMinimizable, &minimizable)) {
-    SetMinimizable(minimizable);
-  }
   bool closable;
   if (options.Get(options::kClosable, &closable)) {
     SetClosable(closable);
   }
-  bool maximizable;
-  if (options.Get(options::kMaximizable, &maximizable)) {
-    SetMaximizable(maximizable);
-  }
 #endif
+  bool movable;
+  if (options.Get(options::kMovable, &movable) && movable) {
+    SetMovable(movable);
+  }
   bool top;
   if (options.Get(options::kAlwaysOnTop, &top) && top) {
     SetAlwaysOnTop(true);
index fe141869cbe13d59a38c76ef512232f7c17a038f..e989ad90d4267fac56363c2529dab745241e9d9f 100644 (file)
@@ -394,12 +394,12 @@ NativeWindowMac::NativeWindowMac(
     useStandardWindow = false;
   }
 
-  NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask;
+  NSUInteger styleMask = NSTitledWindowMask;
   if (minimizable) {
     styleMask |= NSMiniaturizableWindowMask;
   }
-  if (!closable) {
-    styleMask &= ~NSClosableWindowMask;
+  if (closable) {
+    styleMask |= NSClosableWindowMask;
   }
   if (!useStandardWindow || transparent() || !has_frame()) {
     styleMask |= NSTexturedBackgroundWindowMask;
@@ -472,11 +472,6 @@ NativeWindowMac::NativeWindowMac(
     set_force_using_draggable_region(true);
   }
 
-  bool movable;
-  if (options.Get(options::kMovable, &movable)) {
-    [window_ setMovable:movable];
-  }
-
   // On OS X the initial window size doesn't include window frame.
   bool use_content_size = false;
   options.Get(options::kUseContentSize, &use_content_size);
index c51bdce0f5ce60736049fc9ded73d3809cfa751f..216a76ec6b952f3266b4ba330f6acf9dec7940b3 100644 (file)
@@ -59,6 +59,17 @@ const int kMenuBarHeight = 20;
 const int kMenuBarHeight = 25;
 #endif
 
+#if defined(OS_WIN)
+void FlipWindowStyle(HWND handle, bool on, DWORD flag) {
+  DWORD style = ::GetWindowLong(handle, GWL_STYLE);
+  if (on)
+    style |= flag;
+  else
+    style &= ~flag;
+  ::SetWindowLong(handle, GWL_STYLE, style);
+}
+#endif
+
 bool IsAltKey(const content::NativeWebKeyboardEvent& event) {
   return event.windowsKeyCode == ui::VKEY_MENU;
 }
@@ -103,9 +114,9 @@ NativeWindowViews::NativeWindowViews(
       menu_bar_alt_pressed_(false),
       keyboard_event_handler_(new views::UnhandledKeyboardEventHandler),
       use_content_size_(false),
+      movable_(true),
       resizable_(true),
       maximizable_(true),
-      movable_(true),
       minimizable_(true) {
   options.Get(options::kTitle, &title_);
   options.Get(options::kAutoHideMenuBar, &menu_bar_autohide_);
@@ -114,7 +125,6 @@ NativeWindowViews::NativeWindowViews(
   // On Windows we rely on the CanResize() to indicate whether window can be
   // resized, and it should be set before window is created.
   options.Get(options::kResizable, &resizable_);
-  options.Get(options::kMovable, &movable_);
   options.Get(options::kMinimizable, &minimizable_);
   options.Get(options::kMaximizable, &maximizable_);
 #endif
@@ -216,25 +226,29 @@ NativeWindowViews::NativeWindowViews(
     last_window_state_ = ui::SHOW_STATE_FULLSCREEN;
   else
     last_window_state_ = ui::SHOW_STATE_NORMAL;
-
   last_normal_size_ = gfx::Size(widget_size_);
 
-  DWORD style = ::GetWindowLong(GetAcceleratedWidget(), GWL_STYLE);
-  style |= WS_THICKFRAME | WS_CAPTION | WS_MINIMIZEBOX;
+  if (!has_frame()) {
+    // Set Window style so that we get a minimize and maximize animation when
+    // frameless.
+    DWORD frame_style = WS_CAPTION;
+    if (resizable_)
+      frame_style |= WS_THICKFRAME;
+    if (minimizable_)
+      frame_style |= WS_MINIMIZEBOX;
+    if (maximizable_)
+      frame_style |= WS_MAXIMIZEBOX;
+    // We should not show a frame for transparent window.
+    if (transparent())
+      frame_style &= ~(WS_THICKFRAME | WS_CAPTION);
+    ::SetWindowLong(GetAcceleratedWidget(), GWL_STYLE, frame_style);
+  }
 
   if (transparent()) {
-    DWORD ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE);
+    // Transparent window on Windows has to have WS_EX_COMPOSITED style.
+    LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE);
     ex_style |= WS_EX_COMPOSITED;
     ::SetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE, ex_style);
-
-    if (!has_frame()) {
-      // We should not show a frame for transparent window.
-      style &= ~(WS_THICKFRAME | WS_CAPTION);
-    }
-  }
-
-  if (!transparent() || !has_frame()) {
-    ::SetWindowLong(GetAcceleratedWidget(), GWL_STYLE, style);
   }
 #endif
 
@@ -405,18 +419,8 @@ void NativeWindowViews::SetContentSizeConstraints(
 
 void NativeWindowViews::SetResizable(bool resizable) {
 #if defined(OS_WIN)
-  // WS_MAXIMIZEBOX => Maximize button
-  // WS_MINIMIZEBOX => Minimize button
-  // WS_THICKFRAME => Resize handle
-  if (!transparent()) {
-    DWORD style = ::GetWindowLong(GetAcceleratedWidget(), GWL_STYLE);
-    if (resizable) {
-      style |= WS_THICKFRAME;
-    } else {
-      style &= ~(WS_THICKFRAME);
-    }
-    ::SetWindowLong(GetAcceleratedWidget(), GWL_STYLE, style);
-  }
+  if (!transparent())
+    FlipWindowStyle(GetAcceleratedWidget(), resizable, WS_THICKFRAME);
 #elif defined(USE_X11)
   if (resizable != resizable_) {
     // On Linux there is no "resizable" property of a window, we have to set
@@ -437,7 +441,7 @@ void NativeWindowViews::SetResizable(bool resizable) {
 }
 
 bool NativeWindowViews::IsResizable() {
-  return resizable_;
+  return CanResize();
 }
 
 void NativeWindowViews::SetMovable(bool movable) {
@@ -447,51 +451,38 @@ void NativeWindowViews::SetMovable(bool movable) {
 bool NativeWindowViews::IsMovable() {
 #if defined(OS_WIN)
   return movable_;
-#elif defined(USE_X11)
-  return true;
+#else
+  return true;  // Not implemented on Linux.
 #endif
 }
 
 void NativeWindowViews::SetMinimizable(bool minimizable) {
 #if defined(OS_WIN)
-  if (!transparent()) {
-    DWORD style = ::GetWindowLong(GetAcceleratedWidget(), GWL_STYLE);
-    if (minimizable)
-      style |= WS_MINIMIZEBOX;
-    else
-      style &= (~WS_MINIMIZEBOX);
-    ::SetWindowLong(GetAcceleratedWidget(), GWL_STYLE, style);
-  }
+  FlipWindowStyle(GetAcceleratedWidget(), minimizable, WS_MINIMIZEBOX);
 #endif
-
   minimizable_ = minimizable;
 }
 
 bool NativeWindowViews::IsMinimizable() {
 #if defined(OS_WIN)
-  return ::GetWindowLong(GetAcceleratedWidget(), GWL_STYLE) & WS_MINIMIZEBOX;
-#elif defined(USE_X11)
-  return true;
+  return CanMinimize();
+#else
+  return true;  // CanMinimize() Not implemented on Linux.
 #endif
 }
 
 void NativeWindowViews::SetMaximizable(bool maximizable) {
 #if defined(OS_WIN)
-  DWORD style = ::GetWindowLong(GetAcceleratedWidget(), GWL_STYLE);
-  if (maximizable) {
-    style |= WS_MAXIMIZEBOX;
-  } else {
-    style &= (~WS_MAXIMIZEBOX);
-  }
-  ::SetWindowLong(GetAcceleratedWidget(), GWL_STYLE, style);
+  FlipWindowStyle(GetAcceleratedWidget(), maximizable, WS_MAXIMIZEBOX);
 #endif
+  maximizable_ = maximizable;
 }
 
 bool NativeWindowViews::IsMaximizable() {
 #if defined(OS_WIN)
-  return ::GetWindowLong(GetAcceleratedWidget(), GWL_STYLE) & WS_MAXIMIZEBOX;
-#elif defined(USE_X11)
-  return true;
+  return CanMaximize();
+#else
+  return true;  // CanMaximize() Not implemented on Linux.
 #endif
 }
 
@@ -786,7 +777,7 @@ bool NativeWindowViews::CanResize() const {
 }
 
 bool NativeWindowViews::CanMaximize() const {
-  return resizable_;
+  return resizable_ && maximizable_;
 }
 
 bool NativeWindowViews::CanMinimize() const {
index 98339f8aa606c7392367157e126bc131be92fa69..61d0f95042f23c3f549daf93123d2b7c504bd031 100644 (file)
@@ -206,9 +206,9 @@ class NativeWindowViews : public NativeWindow,
   accelerator_util::AcceleratorTable accelerator_table_;
 
   bool use_content_size_;
+  bool movable_;
   bool resizable_;
   bool maximizable_;
-  bool movable_;
   bool minimizable_;
   std::string title_;
   gfx::Size widget_size_;
index 53228d5fdf922df0ad92c288ad8cca14aebf4833..e5ed1975f80f918eb37257f8b244f4cdf3eafc88 100644 (file)
@@ -96,9 +96,8 @@ bool NativeWindowViews::PreHandleMSG(
       return false;
 
     case WM_MOVING: {
-      if (!movable_) {
+      if (!movable_)
         ::GetWindowRect(GetAcceleratedWidget(), (LPRECT)l_param);
-      }
       return false;
     }