Skip to content

Commit

Permalink
Windows: PageVisibility API when other (processes) windows go fullscr…
Browse files Browse the repository at this point in the history
…een.

BUG=XWALK-5503

Some OSs (e.g. Windows and Linux) don't mark windows as hidden on screen
lock or when other opaque windows fully cover them.

The patch here targets Windows and window from any process going fullscreen.
For this, AppBar notifications are used.
Note that this covers e.g. VLC, MS Paint or browsers going fullscreen. It
doesn't cover screensaver or when application windows are maximized.

In the case when current window goes fullscreen, appbar notificaion is also
received. This case is handled, too.
  • Loading branch information
astojilj committed Mar 7, 2016
1 parent dfbc583 commit 48602f4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ui/views/win/hwnd_message_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) {
gfx::win::DirectManipulationHelper::CreateInstance();
if (direct_manipulation_helper_)
direct_manipulation_helper_->Initialize(hwnd());

EnableFullscreenNotifications(true);
}

void HWNDMessageHandler::InitModalType(ui::ModalType modal_type) {
Expand All @@ -398,6 +400,8 @@ void HWNDMessageHandler::Close() {
if (!IsWindow(hwnd()))
return; // No need to do anything.

EnableFullscreenNotifications(false);

// Let's hide ourselves right away.
Hide();

Expand Down Expand Up @@ -915,6 +919,15 @@ LRESULT HWNDMessageHandler::OnWndProc(UINT message,

if (message == WM_ACTIVATE && IsTopLevelWindow(window))
PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param));
if (message == fullscreen_notification_message_) {
// Don't hide/show content if this window goes/back from fullscreen.
if (w_param == ABN_FULLSCREENAPP) {
if (!(this_window_went_fullscreen_ || fullscreen_handler_->fullscreen()))
delegate_->HandleSoftVisibilityChanged(!l_param);
this_window_went_fullscreen_ = l_param &&
fullscreen_handler_->fullscreen();
}
}
return result;
}

Expand Down Expand Up @@ -2472,4 +2485,20 @@ void HWNDMessageHandler::GenerateTouchEvent(ui::EventType event_type,
touch_events->push_back(event);
}

void HWNDMessageHandler::EnableFullscreenNotifications(bool enable) {
APPBARDATA app_bar_data = { sizeof(APPBARDATA), hwnd() };
if (enable) {
// Define a new window message that is guaranteed to be unique.
app_bar_data.uCallbackMessage = RegisterWindowMessage(
L"hwnd_message_handler_fullscreen_notification");
if (app_bar_data.uCallbackMessage &&
SHAppBarMessage(ABM_NEW, &app_bar_data)) {
fullscreen_notification_message_ = app_bar_data.uCallbackMessage;
}
} else {
SHAppBarMessage(ABM_REMOVE, &app_bar_data);
fullscreen_notification_message_ = 0;
}
}

} // namespace views
11 changes: 11 additions & 0 deletions ui/views/win/hwnd_message_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@ class VIEWS_EXPORT HWNDMessageHandler :
base::TimeDelta time_stamp,
TouchEvents* touch_events);

// Register for AppBar notification about other processes going fullscreen.
// |enable| true to register for notification, false to unregister.
void EnableFullscreenNotifications(bool enable);

HWNDMessageHandlerDelegate* delegate_;

scoped_ptr<FullscreenHandler> fullscreen_handler_;
Expand Down Expand Up @@ -531,6 +535,13 @@ class VIEWS_EXPORT HWNDMessageHandler :
// The set of touch devices currently down.
TouchIDs touch_ids_;

// An ID of custom message used to tTrack if fullscreen monitoring is enabled.
UINT fullscreen_notification_message_ = 0;

// Set to true when detected that it is this window that is going fullscreen.
// Used to avoid redundant showing the window when this window exits fullscreen.
bool this_window_went_fullscreen_ = false;

// ScopedRedrawLock ----------------------------------------------------------

// Represents the number of ScopedRedrawLocks active against this widget.
Expand Down

0 comments on commit 48602f4

Please sign in to comment.