]> khamidou — GitHub mirrors - electron.git/commitdiff
views: Implement menubar APIs
authorCheng Zhao <zcbenz@gmail.com>
Wed, 12 Nov 2014 12:32:14 +0000 (20:32 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 12 Nov 2014 12:32:14 +0000 (20:32 +0800)
atom/browser/native_window_views.cc
atom/browser/native_window_views.h

index dd0e662d5f5c0ee6e6529c48ae828d0986167b3b..eb5f31d459749f2bdb4f8669decd2f727bb4a0d0 100644 (file)
@@ -237,6 +237,8 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
   }
 #endif
 
+  // TODO(zcbenz): This was used to force using native frame on Windows 2003, we
+  // should check whether setting it in InitParams can work.
   if (has_frame_) {
     window_->set_frame_type(views::Widget::FrameType::FRAME_TYPE_FORCE_NATIVE);
     window_->FrameTypeChanged();
@@ -559,6 +561,38 @@ void NativeWindowViews::SetProgressBar(double progress) {
 #endif
 }
 
+void NativeWindowViews::SetAutoHideMenuBar(bool auto_hide) {
+  menu_bar_autohide_ = auto_hide;
+}
+
+bool NativeWindowViews::IsMenuBarAutoHide() {
+  return menu_bar_autohide_;
+}
+
+void NativeWindowViews::SetMenuBarVisibility(bool visible) {
+  if (!menu_bar_ || menu_bar_visible_ == visible)
+    return;
+
+  // Always show the accelerator when the auto-hide menu bar shows.
+  if (menu_bar_autohide_)
+    menu_bar_->SetAcceleratorVisibility(visible);
+
+  menu_bar_visible_ = visible;
+  if (visible) {
+    DCHECK_EQ(child_count(), 1);
+    AddChildView(menu_bar_.get());
+  } else {
+    DCHECK_EQ(child_count(), 2);
+    RemoveChildView(menu_bar_.get());
+  }
+
+  Layout();
+}
+
+bool NativeWindowViews::IsMenuBarVisible() {
+  return menu_bar_visible_;
+}
+
 gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() {
   return GetNativeWindow()->GetHost()->GetAcceleratedWidget();
 }
@@ -600,10 +634,8 @@ void NativeWindowViews::OnWidgetActivationChanged(
     GetWebContents()->Focus();
 
   // Hide menu bar when window is blured.
-  if (!active && menu_bar_autohide_ && menu_bar_visible_) {
+  if (!active && menu_bar_autohide_ && menu_bar_visible_)
     SetMenuBarVisibility(false);
-    Layout();
-  }
 }
 
 void NativeWindowViews::DeleteDelegate() {
@@ -695,10 +727,8 @@ gfx::ImageSkia NativeWindowViews::GetDevToolsWindowIcon() {
 
 void NativeWindowViews::HandleMouseDown() {
   // Hide menu bar when web view is clicked.
-  if (menu_bar_autohide_ && menu_bar_visible_) {
+  if (menu_bar_autohide_ && menu_bar_visible_)
     SetMenuBarVisibility(false);
-    Layout();
-  }
 }
 
 void NativeWindowViews::HandleKeyboardEvent(
@@ -718,10 +748,8 @@ void NativeWindowViews::HandleKeyboardEvent(
   if (event.type == blink::WebInputEvent::RawKeyDown && !IsAltKey(event) &&
       IsAltModifier(event)) {
     if (!menu_bar_visible_ &&
-        (menu_bar_->GetAcceleratorIndex(event.windowsKeyCode) != -1)) {
+        (menu_bar_->GetAcceleratorIndex(event.windowsKeyCode) != -1))
       SetMenuBarVisibility(true);
-      Layout();
-    }
     menu_bar_->ActivateAccelerator(event.windowsKeyCode);
     return;
   }
@@ -741,7 +769,6 @@ void NativeWindowViews::HandleKeyboardEvent(
     // When a single Alt is released right after a Alt is pressed:
     menu_bar_alt_pressed_ = false;
     SetMenuBarVisibility(!menu_bar_visible_);
-    Layout();
   } else {
     // When any other keys except single Alt have been pressed/released:
     menu_bar_alt_pressed_ = false;
@@ -779,24 +806,6 @@ gfx::Rect NativeWindowViews::ContentBoundsToWindowBounds(
   return window_bounds;
 }
 
-void NativeWindowViews::SetMenuBarVisibility(bool visible) {
-  if (!menu_bar_)
-    return;
-
-  // Always show the accelerator when the auto-hide menu bar shows.
-  if (menu_bar_autohide_)
-    menu_bar_->SetAcceleratorVisibility(visible);
-
-  menu_bar_visible_ = visible;
-  if (visible) {
-    DCHECK_EQ(child_count(), 1);
-    AddChildView(menu_bar_.get());
-  } else {
-    DCHECK_EQ(child_count(), 2);
-    RemoveChildView(menu_bar_.get());
-  }
-}
-
 // static
 NativeWindow* NativeWindow::Create(content::WebContents* web_contents,
                                    const mate::Dictionary& options) {
index dcb013871497799b924c2be7a58c62944cb25db2..fe7df269173a39b20ac56a619d81311d414e1e20 100644 (file)
@@ -73,6 +73,10 @@ class NativeWindowViews : public NativeWindow,
   void SetMenu(ui::MenuModel* menu_model) override;
   gfx::NativeWindow GetNativeWindow() override;
   void SetProgressBar(double value) override;
+  void SetAutoHideMenuBar(bool auto_hide) override;
+  bool IsMenuBarAutoHide() override;
+  void SetMenuBarVisibility(bool visible) override;
+  bool IsMenuBarVisible() override;
 
   gfx::AcceleratedWidget GetAcceleratedWidget();
 
@@ -126,9 +130,6 @@ class NativeWindowViews : public NativeWindow,
   // in client area we need to substract/add menu bar's height in convertions.
   gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& content_bounds);
 
-  // Show/Hide the menu bar.
-  void SetMenuBarVisibility(bool visible);
-
   scoped_ptr<views::Widget> window_;
   views::View* web_view_;  // Managed by inspectable_web_contents_.