Home | History | Annotate | Download | only in widget
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "ui/views/widget/monitor_win.h"
      6 
      7 #include <shellapi.h>
      8 
      9 #include "base/logging.h"
     10 #include "ui/gfx/rect.h"
     11 
     12 namespace views {
     13 
     14 gfx::Rect GetMonitorBoundsForRect(const gfx::Rect& rect) {
     15   RECT p_rect = rect.ToRECT();
     16   HMONITOR monitor = MonitorFromRect(&p_rect, MONITOR_DEFAULTTONEAREST);
     17   if (monitor) {
     18     MONITORINFO mi = {0};
     19     mi.cbSize = sizeof(mi);
     20     GetMonitorInfo(monitor, &mi);
     21     return gfx::Rect(mi.rcWork);
     22   }
     23   NOTREACHED();
     24   return gfx::Rect();
     25 }
     26 
     27 HWND GetTopmostAutoHideTaskbarForEdge(UINT edge, HMONITOR monitor) {
     28   // NOTE: this may be invoked on a background thread.
     29   APPBARDATA taskbar_data =  { sizeof(APPBARDATA), NULL, 0, edge };
     30   HWND taskbar = reinterpret_cast<HWND>(SHAppBarMessage(ABM_GETAUTOHIDEBAR,
     31                                                         &taskbar_data));
     32   return (::IsWindow(taskbar) && (monitor != NULL) &&
     33          (MonitorFromWindow(taskbar, MONITOR_DEFAULTTONULL) == monitor) &&
     34          (GetWindowLong(taskbar, GWL_EXSTYLE) & WS_EX_TOPMOST)) ?
     35       taskbar : NULL;
     36 }
     37 
     38 }  // namespace views
     39