Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: ui/views/win/hwnd_message_handler.cc

Issue 2826343002: Remove use of WS_EX_COMPOSITED for translucent windows. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/win/hwnd_message_handler.h" 5 #include "ui/views/win/hwnd_message_handler.h"
6 6
7 #include <dwmapi.h> 7 #include <dwmapi.h>
8 #include <oleacc.h> 8 #include <oleacc.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <tchar.h> 10 #include <tchar.h>
(...skipping 22 matching lines...) Expand all
33 #include "ui/events/event.h" 33 #include "ui/events/event.h"
34 #include "ui/events/event_constants.h" 34 #include "ui/events/event_constants.h"
35 #include "ui/events/event_utils.h" 35 #include "ui/events/event_utils.h"
36 #include "ui/events/keycodes/keyboard_code_conversion_win.h" 36 #include "ui/events/keycodes/keyboard_code_conversion_win.h"
37 #include "ui/events/win/system_event_state_lookup.h" 37 #include "ui/events/win/system_event_state_lookup.h"
38 #include "ui/gfx/canvas.h" 38 #include "ui/gfx/canvas.h"
39 #include "ui/gfx/geometry/insets.h" 39 #include "ui/gfx/geometry/insets.h"
40 #include "ui/gfx/icon_util.h" 40 #include "ui/gfx/icon_util.h"
41 #include "ui/gfx/path.h" 41 #include "ui/gfx/path.h"
42 #include "ui/gfx/path_win.h" 42 #include "ui/gfx/path_win.h"
43 #include "ui/gfx/win/constants.h"
43 #include "ui/gfx/win/direct_manipulation.h" 44 #include "ui/gfx/win/direct_manipulation.h"
44 #include "ui/gfx/win/hwnd_util.h" 45 #include "ui/gfx/win/hwnd_util.h"
45 #include "ui/gfx/win/rendering_window_manager.h" 46 #include "ui/gfx/win/rendering_window_manager.h"
46 #include "ui/native_theme/native_theme_win.h" 47 #include "ui/native_theme/native_theme_win.h"
47 #include "ui/views/views_delegate.h" 48 #include "ui/views/views_delegate.h"
48 #include "ui/views/widget/widget_hwnd_utils.h" 49 #include "ui/views/widget/widget_hwnd_utils.h"
49 #include "ui/views/win/fullscreen_handler.h" 50 #include "ui/views/win/fullscreen_handler.h"
50 #include "ui/views/win/hwnd_message_handler_delegate.h" 51 #include "ui/views/win/hwnd_message_handler_delegate.h"
51 #include "ui/views/win/scoped_fullscreen_visibility.h" 52 #include "ui/views/win/scoped_fullscreen_visibility.h"
52 #include "ui/views/win/windows_session_change_observer.h" 53 #include "ui/views/win/windows_session_change_observer.h"
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 } 522 }
522 523
523 void HWNDMessageHandler::SetBounds(const gfx::Rect& bounds_in_pixels, 524 void HWNDMessageHandler::SetBounds(const gfx::Rect& bounds_in_pixels,
524 bool force_size_changed) { 525 bool force_size_changed) {
525 background_fullscreen_hack_ = false; 526 background_fullscreen_hack_ = false;
526 SetBoundsInternal(bounds_in_pixels, force_size_changed); 527 SetBoundsInternal(bounds_in_pixels, force_size_changed);
527 } 528 }
528 529
529 void HWNDMessageHandler::SetDwmFrameExtension(DwmFrameState state) { 530 void HWNDMessageHandler::SetDwmFrameExtension(DwmFrameState state) {
530 if (!delegate_->HasFrame() && ui::win::IsAeroGlassEnabled() && 531 if (!delegate_->HasFrame() && ui::win::IsAeroGlassEnabled() &&
531 (window_ex_style() & WS_EX_COMPOSITED) == 0) { 532 !translucent_) {
532 MARGINS m = {0, 0, 0, 0}; 533 MARGINS m = {0, 0, 0, 0};
533 if (state == DwmFrameState::ON) 534 if (state == DwmFrameState::ON)
534 m = {0, 0, 1, 0}; 535 m = {0, 0, 1, 0};
535 DwmExtendFrameIntoClientArea(hwnd(), &m); 536 DwmExtendFrameIntoClientArea(hwnd(), &m);
536 } 537 }
537 } 538 }
538 539
539 void HWNDMessageHandler::SetSize(const gfx::Size& size) { 540 void HWNDMessageHandler::SetSize(const gfx::Size& size) {
540 SetWindowPos(hwnd(), NULL, 0, 0, size.width(), size.height(), 541 SetWindowPos(hwnd(), NULL, 0, 0, size.width(), size.height(),
541 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE); 542 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 if (!fullscreen && dwm_transition_desired_) 847 if (!fullscreen && dwm_transition_desired_)
847 PerformDwmTransition(); 848 PerformDwmTransition();
848 } 849 }
849 850
850 void HWNDMessageHandler::SizeConstraintsChanged() { 851 void HWNDMessageHandler::SizeConstraintsChanged() {
851 LONG style = GetWindowLong(hwnd(), GWL_STYLE); 852 LONG style = GetWindowLong(hwnd(), GWL_STYLE);
852 // Ignore if this is not a standard window. 853 // Ignore if this is not a standard window.
853 if (style & (WS_POPUP | WS_CHILD)) 854 if (style & (WS_POPUP | WS_CHILD))
854 return; 855 return;
855 856
856 LONG exstyle = GetWindowLong(hwnd(), GWL_EXSTYLE); 857 // Windows cannot have WS_THICKFRAME set if translucent.
857 // Windows cannot have WS_THICKFRAME set if WS_EX_COMPOSITED is set.
858 // See CalculateWindowStylesFromInitParams(). 858 // See CalculateWindowStylesFromInitParams().
859 if (delegate_->CanResize() && (exstyle & WS_EX_COMPOSITED) == 0) { 859 if (delegate_->CanResize() && !translucent_) {
860 style |= WS_THICKFRAME | WS_MAXIMIZEBOX; 860 style |= WS_THICKFRAME | WS_MAXIMIZEBOX;
861 if (!delegate_->CanMaximize()) 861 if (!delegate_->CanMaximize())
862 style &= ~WS_MAXIMIZEBOX; 862 style &= ~WS_MAXIMIZEBOX;
863 } else { 863 } else {
864 style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX); 864 style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX);
865 } 865 }
866 if (delegate_->CanMinimize()) { 866 if (delegate_->CanMinimize()) {
867 style |= WS_MINIMIZEBOX; 867 style |= WS_MINIMIZEBOX;
868 } else { 868 } else {
869 style &= ~WS_MINIMIZEBOX; 869 style &= ~WS_MINIMIZEBOX;
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 return true; 1170 return true;
1171 } 1171 }
1172 1172
1173 *insets = gfx::Insets(); 1173 *insets = gfx::Insets();
1174 return true; 1174 return true;
1175 } 1175 }
1176 1176
1177 void HWNDMessageHandler::ResetWindowRegion(bool force, bool redraw) { 1177 void HWNDMessageHandler::ResetWindowRegion(bool force, bool redraw) {
1178 // A native frame uses the native window region, and we don't want to mess 1178 // A native frame uses the native window region, and we don't want to mess
1179 // with it. 1179 // with it.
1180 // WS_EX_COMPOSITED is used instead of WS_EX_LAYERED under aura. WS_EX_LAYERED 1180 // WS_EX_LAYERED automatically makes clicks on transparent pixels fall
1181 // automatically makes clicks on transparent pixels fall through, that isn't 1181 // through, but that isn't the case when using Direct3D to draw transparent
1182 // the case with WS_EX_COMPOSITED. So, we route WS_EX_COMPOSITED through to 1182 // windows. So we route translucent windows throught to the delegate to
1183 // the delegate to allow for a custom hit mask. 1183 // allow for a custom hit mask.
1184 if ((window_ex_style() & WS_EX_COMPOSITED) == 0 && 1184 if (!translucent_ && !custom_window_region_.is_valid() &&
1185 !custom_window_region_.is_valid() &&
1186 (IsFrameSystemDrawn() || !delegate_->HasNonClientView())) { 1185 (IsFrameSystemDrawn() || !delegate_->HasNonClientView())) {
1187 if (force) 1186 if (force)
1188 SetWindowRgn(hwnd(), NULL, redraw); 1187 SetWindowRgn(hwnd(), NULL, redraw);
1189 return; 1188 return;
1190 } 1189 }
1191 1190
1192 // Changing the window region is going to force a paint. Only change the 1191 // Changing the window region is going to force a paint. Only change the
1193 // window region if the region really differs. 1192 // window region if the region really differs.
1194 base::win::ScopedRegion current_rgn(CreateRectRgn(0, 0, 0, 0)); 1193 base::win::ScopedRegion current_rgn(CreateRectRgn(0, 0, 0, 0));
1195 GetWindowRgn(hwnd(), current_rgn.get()); 1194 GetWindowRgn(hwnd(), current_rgn.get());
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 void HWNDMessageHandler::OnCommand(UINT notification_code, 1333 void HWNDMessageHandler::OnCommand(UINT notification_code,
1335 int command, 1334 int command,
1336 HWND window) { 1335 HWND window) {
1337 // If the notification code is > 1 it means it is control specific and we 1336 // If the notification code is > 1 it means it is control specific and we
1338 // should ignore it. 1337 // should ignore it.
1339 if (notification_code > 1 || delegate_->HandleAppCommand(command)) 1338 if (notification_code > 1 || delegate_->HandleAppCommand(command))
1340 SetMsgHandled(FALSE); 1339 SetMsgHandled(FALSE);
1341 } 1340 }
1342 1341
1343 LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) { 1342 LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) {
1344 if (window_ex_style() & WS_EX_COMPOSITED) { 1343 if (translucent_) {
1345 // This is part of the magic to emulate layered windows with Aura 1344 // This is part of the magic to emulate layered windows with Aura
1346 // see the explanation elsewere when we set WS_EX_COMPOSITED style. 1345 // see the explanation elsewere when we set translucent_.
1347 MARGINS margins = {-1, -1, -1, -1}; 1346 MARGINS margins = {-1, -1, -1, -1};
1348 DwmExtendFrameIntoClientArea(hwnd(), &margins); 1347 DwmExtendFrameIntoClientArea(hwnd(), &margins);
1348
1349 ::SetProp(hwnd(), gfx::kChromeWindowTranslucent,
1350 reinterpret_cast<HANDLE>(1));
1349 } 1351 }
1350 1352
1351 fullscreen_handler_->set_hwnd(hwnd()); 1353 fullscreen_handler_->set_hwnd(hwnd());
1352 1354
1353 // This message initializes the window so that focus border are shown for 1355 // This message initializes the window so that focus border are shown for
1354 // windows. 1356 // windows.
1355 SendMessage(hwnd(), 1357 SendMessage(hwnd(),
1356 WM_CHANGEUISTATE, 1358 WM_CHANGEUISTATE,
1357 MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 1359 MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS),
1358 0); 1360 0);
(...skipping 21 matching lines...) Expand all
1380 base::Unretained(this)))); 1382 base::Unretained(this))));
1381 1383
1382 float scale_factor = display::win::ScreenWin::GetScaleFactorForHWND(hwnd()); 1384 float scale_factor = display::win::ScreenWin::GetScaleFactorForHWND(hwnd());
1383 dpi_ = display::win::GetDPIFromScalingFactor(scale_factor); 1385 dpi_ = display::win::GetDPIFromScalingFactor(scale_factor);
1384 1386
1385 // TODO(beng): move more of NWW::OnCreate here. 1387 // TODO(beng): move more of NWW::OnCreate here.
1386 return 0; 1388 return 0;
1387 } 1389 }
1388 1390
1389 void HWNDMessageHandler::OnDestroy() { 1391 void HWNDMessageHandler::OnDestroy() {
1392 ::RemoveProp(hwnd(), gfx::kChromeWindowTranslucent);
1390 windows_session_change_observer_.reset(nullptr); 1393 windows_session_change_observer_.reset(nullptr);
1391 delegate_->HandleDestroying(); 1394 delegate_->HandleDestroying();
1392 // If the window going away is a fullscreen window then remove its references 1395 // If the window going away is a fullscreen window then remove its references
1393 // from the full screen window map. 1396 // from the full screen window map.
1394 for (auto iter = fullscreen_monitor_map_.Get().begin(); 1397 for (auto iter = fullscreen_monitor_map_.Get().begin();
1395 iter != fullscreen_monitor_map_.Get().end(); 1398 iter != fullscreen_monitor_map_.Get().end();
1396 iter++) { 1399 iter++) {
1397 if (iter->second == this) { 1400 if (iter->second == this) {
1398 fullscreen_monitor_map_.Get().erase(iter); 1401 fullscreen_monitor_map_.Get().erase(iter);
1399 break; 1402 break;
(...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after
2907 MONITORINFO monitor_info = {sizeof(monitor_info)}; 2910 MONITORINFO monitor_info = {sizeof(monitor_info)};
2908 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), 2911 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY),
2909 &monitor_info); 2912 &monitor_info);
2910 gfx::Rect shrunk_rect(monitor_info.rcMonitor); 2913 gfx::Rect shrunk_rect(monitor_info.rcMonitor);
2911 shrunk_rect.set_height(shrunk_rect.height() - 1); 2914 shrunk_rect.set_height(shrunk_rect.height() - 1);
2912 background_fullscreen_hack_ = true; 2915 background_fullscreen_hack_ = true;
2913 SetBoundsInternal(shrunk_rect, false); 2916 SetBoundsInternal(shrunk_rect, false);
2914 } 2917 }
2915 2918
2916 } // namespace views 2919 } // namespace views
OLDNEW
« ui/views/win/hwnd_message_handler.h ('K') | « ui/views/win/hwnd_message_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698