Reorgnize how attributes work
This commit is contained in:
parent
ae7e96f181
commit
d704b3f7ba
5 changed files with 55 additions and 78 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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_;
|
||||
|
|
|
@ -96,9 +96,8 @@ bool NativeWindowViews::PreHandleMSG(
|
|||
return false;
|
||||
|
||||
case WM_MOVING: {
|
||||
if (!movable_) {
|
||||
if (!movable_)
|
||||
::GetWindowRect(GetAcceleratedWidget(), (LPRECT)l_param);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue