Remove MenuLayout in favor of NativeWindowViews::Layout
This commit is contained in:
parent
8b9f7e5b00
commit
638eae1080
5 changed files with 40 additions and 133 deletions
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
#include "atom/browser/native_browser_view.h"
|
#include "atom/browser/native_browser_view.h"
|
||||||
#include "atom/browser/ui/views/menu_bar.h"
|
#include "atom/browser/ui/views/menu_bar.h"
|
||||||
#include "atom/browser/ui/views/menu_layout.h"
|
|
||||||
#include "atom/browser/window_list.h"
|
#include "atom/browser/window_list.h"
|
||||||
#include "atom/common/color_util.h"
|
#include "atom/common/color_util.h"
|
||||||
#include "atom/common/draggable_region.h"
|
#include "atom/common/draggable_region.h"
|
||||||
|
@ -71,6 +70,20 @@ const int kMenuBarHeight = 25;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
|
gfx::Rect SubtractBorderSize(gfx::Rect bounds) {
|
||||||
|
gfx::Point borderSize = gfx::Point(
|
||||||
|
GetSystemMetrics(SM_CXSIZEFRAME) - 1, // width
|
||||||
|
GetSystemMetrics(SM_CYSIZEFRAME) - 1); // height
|
||||||
|
gfx::Point dpiAdjustedSize =
|
||||||
|
display::win::ScreenWin::ScreenToDIPPoint(borderSize);
|
||||||
|
|
||||||
|
bounds.set_x(bounds.x() + dpiAdjustedSize.x());
|
||||||
|
bounds.set_y(bounds.y() + dpiAdjustedSize.y());
|
||||||
|
bounds.set_width(bounds.width() - 2 * dpiAdjustedSize.x());
|
||||||
|
bounds.set_height(bounds.height() - 2 * dpiAdjustedSize.y());
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
|
|
||||||
void FlipWindowStyle(HWND handle, bool on, DWORD flag) {
|
void FlipWindowStyle(HWND handle, bool on, DWORD flag) {
|
||||||
DWORD style = ::GetWindowLong(handle, GWL_STYLE);
|
DWORD style = ::GetWindowLong(handle, GWL_STYLE);
|
||||||
if (on)
|
if (on)
|
||||||
|
@ -276,9 +289,6 @@ NativeWindowViews::NativeWindowViews(
|
||||||
SetWindowType(GetAcceleratedWidget(), window_type);
|
SetWindowType(GetAcceleratedWidget(), window_type);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Add web view.
|
|
||||||
SetLayoutManager(new MenuLayout(this, kMenuBarHeight));
|
|
||||||
|
|
||||||
AddChildView(web_view_);
|
AddChildView(web_view_);
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
|
@ -1264,6 +1274,31 @@ void NativeWindowViews::HandleKeyboardEvent(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindowViews::Layout() {
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
// Reserve border space for maximized frameless window so we won't have the
|
||||||
|
// content go outside of screen.
|
||||||
|
if (!has_frame() && IsMaximized()) {
|
||||||
|
gfx::Rect bounds = SubtractBorderSize(GetContentsBounds());
|
||||||
|
web_view_->SetBoundsRect(bounds);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const auto size = GetContentsBounds().size();
|
||||||
|
const auto menu_bar_bounds =
|
||||||
|
menu_bar_ ? gfx::Rect(0, 0, size.width(), kMenuBarHeight) : gfx::Rect();
|
||||||
|
if (menu_bar_) {
|
||||||
|
menu_bar_->SetBoundsRect(menu_bar_bounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (web_view_) {
|
||||||
|
web_view_->SetBoundsRect(
|
||||||
|
gfx::Rect(0, menu_bar_bounds.height(), size.width(),
|
||||||
|
size.height() - menu_bar_bounds.height()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gfx::Size NativeWindowViews::GetMinimumSize() {
|
gfx::Size NativeWindowViews::GetMinimumSize() {
|
||||||
return NativeWindow::GetMinimumSize();
|
return NativeWindow::GetMinimumSize();
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,6 +177,7 @@ class NativeWindowViews : public NativeWindow,
|
||||||
const content::NativeWebKeyboardEvent& event) override;
|
const content::NativeWebKeyboardEvent& event) override;
|
||||||
|
|
||||||
// views::View:
|
// views::View:
|
||||||
|
void Layout() override;
|
||||||
gfx::Size GetMinimumSize() override;
|
gfx::Size GetMinimumSize() override;
|
||||||
gfx::Size GetMaximumSize() override;
|
gfx::Size GetMaximumSize() override;
|
||||||
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
||||||
|
|
|
@ -1,91 +0,0 @@
|
||||||
// Copyright (c) 2014 GitHub, Inc.
|
|
||||||
// Use of this source code is governed by the MIT license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
#include "atom/browser/ui/views/menu_layout.h"
|
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
|
||||||
#include "atom/browser/native_window_views.h"
|
|
||||||
#include "ui/display/win/screen_win.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace atom {
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
|
||||||
gfx::Rect SubtractBorderSize(gfx::Rect bounds) {
|
|
||||||
gfx::Point borderSize = gfx::Point(
|
|
||||||
GetSystemMetrics(SM_CXSIZEFRAME) - 1, // width
|
|
||||||
GetSystemMetrics(SM_CYSIZEFRAME) - 1); // height
|
|
||||||
gfx::Point dpiAdjustedSize =
|
|
||||||
display::win::ScreenWin::ScreenToDIPPoint(borderSize);
|
|
||||||
|
|
||||||
bounds.set_x(bounds.x() + dpiAdjustedSize.x());
|
|
||||||
bounds.set_y(bounds.y() + dpiAdjustedSize.y());
|
|
||||||
bounds.set_width(bounds.width() - 2 * dpiAdjustedSize.x());
|
|
||||||
bounds.set_height(bounds.height() - 2 * dpiAdjustedSize.y());
|
|
||||||
return bounds;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
MenuLayout::MenuLayout(NativeWindowViews* window, int menu_height)
|
|
||||||
: window_(window),
|
|
||||||
menu_height_(menu_height) {
|
|
||||||
}
|
|
||||||
|
|
||||||
MenuLayout::~MenuLayout() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void MenuLayout::Layout(views::View* host) {
|
|
||||||
#if defined(OS_WIN)
|
|
||||||
// Reserve border space for maximized frameless window so we won't have the
|
|
||||||
// content go outside of screen.
|
|
||||||
if (!window_->has_frame() && window_->IsMaximized()) {
|
|
||||||
gfx::Rect bounds = SubtractBorderSize(host->GetContentsBounds());
|
|
||||||
host->child_at(0)->SetBoundsRect(bounds);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!HasMenu(host)) {
|
|
||||||
views::FillLayout::Layout(host);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
gfx::Size size = host->GetContentsBounds().size();
|
|
||||||
gfx::Rect menu_Bar_bounds = gfx::Rect(0, 0, size.width(), menu_height_);
|
|
||||||
gfx::Rect web_view_bounds = gfx::Rect(
|
|
||||||
0, menu_height_, size.width(), size.height() - menu_height_);
|
|
||||||
|
|
||||||
views::View* web_view = host->child_at(0);
|
|
||||||
views::View* menu_bar = host->child_at(1);
|
|
||||||
web_view->SetBoundsRect(web_view_bounds);
|
|
||||||
menu_bar->SetBoundsRect(menu_Bar_bounds);
|
|
||||||
}
|
|
||||||
|
|
||||||
gfx::Size MenuLayout::GetPreferredSize(const views::View* host) const {
|
|
||||||
gfx::Size size = views::FillLayout::GetPreferredSize(host);
|
|
||||||
if (!HasMenu(host))
|
|
||||||
return size;
|
|
||||||
|
|
||||||
size.set_height(size.height() + menu_height_);
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
int MenuLayout::GetPreferredHeightForWidth(
|
|
||||||
const views::View* host, int width) const {
|
|
||||||
int height = views::FillLayout::GetPreferredHeightForWidth(host, width);
|
|
||||||
if (!HasMenu(host))
|
|
||||||
return height;
|
|
||||||
|
|
||||||
return height + menu_height_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MenuLayout::HasMenu(const views::View* host) const {
|
|
||||||
return host->child_count() == 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace atom
|
|
|
@ -1,36 +0,0 @@
|
||||||
// Copyright (c) 2014 GitHub, Inc.
|
|
||||||
// Use of this source code is governed by the MIT license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
#ifndef ATOM_BROWSER_UI_VIEWS_MENU_LAYOUT_H_
|
|
||||||
#define ATOM_BROWSER_UI_VIEWS_MENU_LAYOUT_H_
|
|
||||||
|
|
||||||
#include "ui/views/layout/fill_layout.h"
|
|
||||||
|
|
||||||
namespace atom {
|
|
||||||
|
|
||||||
class NativeWindowViews;
|
|
||||||
|
|
||||||
class MenuLayout : public views::FillLayout {
|
|
||||||
public:
|
|
||||||
MenuLayout(NativeWindowViews* window, int menu_height);
|
|
||||||
virtual ~MenuLayout();
|
|
||||||
|
|
||||||
// views::LayoutManager:
|
|
||||||
void Layout(views::View* host) override;
|
|
||||||
gfx::Size GetPreferredSize(const views::View* host) const override;
|
|
||||||
int GetPreferredHeightForWidth(
|
|
||||||
const views::View* host, int width) const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool HasMenu(const views::View* host) const;
|
|
||||||
|
|
||||||
NativeWindowViews* window_;
|
|
||||||
int menu_height_;
|
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(MenuLayout);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace atom
|
|
||||||
|
|
||||||
#endif // ATOM_BROWSER_UI_VIEWS_MENU_LAYOUT_H_
|
|
|
@ -322,8 +322,6 @@
|
||||||
'atom/browser/ui/views/menu_bar.h',
|
'atom/browser/ui/views/menu_bar.h',
|
||||||
'atom/browser/ui/views/menu_delegate.cc',
|
'atom/browser/ui/views/menu_delegate.cc',
|
||||||
'atom/browser/ui/views/menu_delegate.h',
|
'atom/browser/ui/views/menu_delegate.h',
|
||||||
'atom/browser/ui/views/menu_layout.cc',
|
|
||||||
'atom/browser/ui/views/menu_layout.h',
|
|
||||||
'atom/browser/ui/views/menu_model_adapter.cc',
|
'atom/browser/ui/views/menu_model_adapter.cc',
|
||||||
'atom/browser/ui/views/menu_model_adapter.h',
|
'atom/browser/ui/views/menu_model_adapter.h',
|
||||||
'atom/browser/ui/views/native_frame_view.cc',
|
'atom/browser/ui/views/native_frame_view.cc',
|
||||||
|
|
Loading…
Reference in a new issue