menu_bar_autohide_(false),
menu_bar_visible_(false),
menu_bar_alt_pressed_(false),
-#if defined(OS_WIN)
- is_minimized_(false),
-#endif
keyboard_event_handler_(new views::UnhandledKeyboardEventHandler),
use_content_size_(false),
resizable_(true) {
window_->Init(params);
+ bool fullscreen = false;
+ options.Get(switches::kFullscreen, &fullscreen);
+
#if defined(USE_X11)
// Start monitoring window states.
window_state_watcher_.reset(new WindowStateWatcher(this));
}
// Before the window is mapped, there is no SHOW_FULLSCREEN_STATE.
- bool fullscreen = false;
- if (options.Get(switches::kFullscreen, & fullscreen) && fullscreen) {
+ if (fullscreen) {
state_atom_list.push_back(GetAtom("_NET_WM_STATE_FULLSCREEN"));
}
bounds = ContentBoundsToWindowBounds(bounds);
#if defined(OS_WIN)
+ // Save initial window state.
+ if (fullscreen)
+ last_window_state_ = ui::SHOW_STATE_FULLSCREEN;
+ else
+ last_window_state_ = ui::SHOW_STATE_NORMAL;
+
if (!has_frame()) {
// Set Window style so that we get a minimize and maximize animation when
// frameless.
void NativeWindowViews::SetFullScreen(bool fullscreen) {
#if defined(OS_WIN)
// There is no native fullscreen state on Windows.
- window_->SetFullscreen(fullscreen);
- if (fullscreen)
+ if (fullscreen) {
+ last_window_state_ = ui::SHOW_STATE_FULLSCREEN;
NotifyWindowEnterFullScreen();
- else
+ } else {
+ last_window_state_ = ui::SHOW_STATE_NORMAL;
NotifyWindowLeaveFullScreen();
+ }
+ // We set the new value after notifying, so we can handle the size event
+ // correctly.
+ window_->SetFullscreen(fullscreen);
#else
if (IsVisible())
window_->SetFullscreen(fullscreen);
#if defined(OS_WIN)
bool NativeWindowViews::ExecuteWindowsCommand(int command_id) {
- // Windows uses the 4 lower order bits of |command_id| for type-specific
- // information so we must exclude this when comparing.
- static const int sc_mask = 0xFFF0;
- if ((command_id & sc_mask) == SC_MINIMIZE) {
- NotifyWindowMinimize();
- is_minimized_ = true;
- } else if ((command_id & sc_mask) == SC_RESTORE) {
- if (is_minimized_)
- NotifyWindowRestore();
- else
- NotifyWindowUnmaximize();
- is_minimized_ = false;
- } else if ((command_id & sc_mask) == SC_MAXIMIZE) {
- NotifyWindowMaximize();
- } else {
- std::string command = AppCommandToString(command_id);
- NotifyWindowExecuteWindowsCommand(command);
- }
+ std::string command = AppCommandToString(command_id);
+ NotifyWindowExecuteWindowsCommand(command);
return false;
}
#endif
#if defined(OS_WIN)
bool NativeWindowViews::PreHandleMSG(
UINT message, WPARAM w_param, LPARAM l_param, LRESULT* result) {
- // Handle thumbar button click message.
- if (message == WM_COMMAND && HIWORD(w_param) == THBN_CLICKED)
- return taskbar_host_.HandleThumbarButtonEvent(LOWORD(w_param));
- else
- return false;
+ switch (message) {
+ case WM_COMMAND:
+ // Handle thumbar button click message.
+ if (HIWORD(w_param) == THBN_CLICKED)
+ return taskbar_host_.HandleThumbarButtonEvent(LOWORD(w_param));
+ return false;
+ case WM_SIZE:
+ // Handle window state change.
+ HandleSizeEvent(w_param, l_param);
+ return false;
+ default:
+ return false;
+ }
+}
+
+void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
+ // Here we handle the WM_SIZE event in order to figure out what is the current
+ // window state and notify the user accordingly.
+ switch (w_param) {
+ case SIZE_MAXIMIZED:
+ last_window_state_ = ui::SHOW_STATE_MAXIMIZED;
+ NotifyWindowMaximize();
+ break;
+ case SIZE_MINIMIZED:
+ last_window_state_ = ui::SHOW_STATE_MINIMIZED;
+ NotifyWindowMinimize();
+ break;
+ case SIZE_RESTORED:
+ if (last_window_state_ == ui::SHOW_STATE_NORMAL)
+ return;
+
+ switch (last_window_state_) {
+ case ui::SHOW_STATE_MAXIMIZED:
+ last_window_state_ = ui::SHOW_STATE_NORMAL;
+ NotifyWindowUnmaximize();
+ break;
+ case ui::SHOW_STATE_MINIMIZED:
+ if (IsFullscreen()) {
+ last_window_state_ = ui::SHOW_STATE_FULLSCREEN;
+ NotifyWindowEnterFullScreen();
+ } else {
+ last_window_state_ = ui::SHOW_STATE_NORMAL;
+ NotifyWindowRestore();
+ }
+ break;
+ }
+ break;
+ }
}
#endif