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

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: post-review changes 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
« no previous file with comments | « ui/views/win/hwnd_message_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 } 521 }
522 522
523 void HWNDMessageHandler::SetBounds(const gfx::Rect& bounds_in_pixels, 523 void HWNDMessageHandler::SetBounds(const gfx::Rect& bounds_in_pixels,
524 bool force_size_changed) { 524 bool force_size_changed) {
525 background_fullscreen_hack_ = false; 525 background_fullscreen_hack_ = false;
526 SetBoundsInternal(bounds_in_pixels, force_size_changed); 526 SetBoundsInternal(bounds_in_pixels, force_size_changed);
527 } 527 }
528 528
529 void HWNDMessageHandler::SetDwmFrameExtension(DwmFrameState state) { 529 void HWNDMessageHandler::SetDwmFrameExtension(DwmFrameState state) {
530 if (!delegate_->HasFrame() && ui::win::IsAeroGlassEnabled() && 530 if (!delegate_->HasFrame() && ui::win::IsAeroGlassEnabled() &&
531 (window_ex_style() & WS_EX_COMPOSITED) == 0) { 531 !is_translucent_) {
532 MARGINS m = {0, 0, 0, 0}; 532 MARGINS m = {0, 0, 0, 0};
533 if (state == DwmFrameState::ON) 533 if (state == DwmFrameState::ON)
534 m = {0, 0, 1, 0}; 534 m = {0, 0, 1, 0};
535 DwmExtendFrameIntoClientArea(hwnd(), &m); 535 DwmExtendFrameIntoClientArea(hwnd(), &m);
536 } 536 }
537 } 537 }
538 538
539 void HWNDMessageHandler::SetSize(const gfx::Size& size) { 539 void HWNDMessageHandler::SetSize(const gfx::Size& size) {
540 SetWindowPos(hwnd(), NULL, 0, 0, size.width(), size.height(), 540 SetWindowPos(hwnd(), NULL, 0, 0, size.width(), size.height(),
541 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE); 541 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 if (!fullscreen && dwm_transition_desired_) 846 if (!fullscreen && dwm_transition_desired_)
847 PerformDwmTransition(); 847 PerformDwmTransition();
848 } 848 }
849 849
850 void HWNDMessageHandler::SizeConstraintsChanged() { 850 void HWNDMessageHandler::SizeConstraintsChanged() {
851 LONG style = GetWindowLong(hwnd(), GWL_STYLE); 851 LONG style = GetWindowLong(hwnd(), GWL_STYLE);
852 // Ignore if this is not a standard window. 852 // Ignore if this is not a standard window.
853 if (style & (WS_POPUP | WS_CHILD)) 853 if (style & (WS_POPUP | WS_CHILD))
854 return; 854 return;
855 855
856 LONG exstyle = GetWindowLong(hwnd(), GWL_EXSTYLE); 856 // Windows cannot have WS_THICKFRAME set if translucent.
857 // Windows cannot have WS_THICKFRAME set if WS_EX_COMPOSITED is set.
858 // See CalculateWindowStylesFromInitParams(). 857 // See CalculateWindowStylesFromInitParams().
859 if (delegate_->CanResize() && (exstyle & WS_EX_COMPOSITED) == 0) { 858 if (delegate_->CanResize() && !is_translucent_) {
860 style |= WS_THICKFRAME | WS_MAXIMIZEBOX; 859 style |= WS_THICKFRAME | WS_MAXIMIZEBOX;
861 if (!delegate_->CanMaximize()) 860 if (!delegate_->CanMaximize())
862 style &= ~WS_MAXIMIZEBOX; 861 style &= ~WS_MAXIMIZEBOX;
863 } else { 862 } else {
864 style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX); 863 style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX);
865 } 864 }
866 if (delegate_->CanMinimize()) { 865 if (delegate_->CanMinimize()) {
867 style |= WS_MINIMIZEBOX; 866 style |= WS_MINIMIZEBOX;
868 } else { 867 } else {
869 style &= ~WS_MINIMIZEBOX; 868 style &= ~WS_MINIMIZEBOX;
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 return true; 1169 return true;
1171 } 1170 }
1172 1171
1173 *insets = gfx::Insets(); 1172 *insets = gfx::Insets();
1174 return true; 1173 return true;
1175 } 1174 }
1176 1175
1177 void HWNDMessageHandler::ResetWindowRegion(bool force, bool redraw) { 1176 void HWNDMessageHandler::ResetWindowRegion(bool force, bool redraw) {
1178 // A native frame uses the native window region, and we don't want to mess 1177 // A native frame uses the native window region, and we don't want to mess
1179 // with it. 1178 // with it.
1180 // WS_EX_COMPOSITED is used instead of WS_EX_LAYERED under aura. WS_EX_LAYERED 1179 // WS_EX_LAYERED automatically makes clicks on transparent pixels fall
1181 // automatically makes clicks on transparent pixels fall through, that isn't 1180 // 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 1181 // windows. So we route translucent windows throught to the delegate to
1183 // the delegate to allow for a custom hit mask. 1182 // allow for a custom hit mask.
1184 if ((window_ex_style() & WS_EX_COMPOSITED) == 0 && 1183 if (!is_translucent_ && !custom_window_region_.is_valid() &&
1185 !custom_window_region_.is_valid() &&
1186 (IsFrameSystemDrawn() || !delegate_->HasNonClientView())) { 1184 (IsFrameSystemDrawn() || !delegate_->HasNonClientView())) {
1187 if (force) 1185 if (force)
1188 SetWindowRgn(hwnd(), NULL, redraw); 1186 SetWindowRgn(hwnd(), NULL, redraw);
1189 return; 1187 return;
1190 } 1188 }
1191 1189
1192 // Changing the window region is going to force a paint. Only change the 1190 // Changing the window region is going to force a paint. Only change the
1193 // window region if the region really differs. 1191 // window region if the region really differs.
1194 base::win::ScopedRegion current_rgn(CreateRectRgn(0, 0, 0, 0)); 1192 base::win::ScopedRegion current_rgn(CreateRectRgn(0, 0, 0, 0));
1195 GetWindowRgn(hwnd(), current_rgn.get()); 1193 GetWindowRgn(hwnd(), current_rgn.get());
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1334 void HWNDMessageHandler::OnCommand(UINT notification_code, 1332 void HWNDMessageHandler::OnCommand(UINT notification_code,
1335 int command, 1333 int command,
1336 HWND window) { 1334 HWND window) {
1337 // If the notification code is > 1 it means it is control specific and we 1335 // If the notification code is > 1 it means it is control specific and we
1338 // should ignore it. 1336 // should ignore it.
1339 if (notification_code > 1 || delegate_->HandleAppCommand(command)) 1337 if (notification_code > 1 || delegate_->HandleAppCommand(command))
1340 SetMsgHandled(FALSE); 1338 SetMsgHandled(FALSE);
1341 } 1339 }
1342 1340
1343 LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) { 1341 LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) {
1344 if (window_ex_style() & WS_EX_COMPOSITED) { 1342 if (is_translucent_) {
1345 // This is part of the magic to emulate layered windows with Aura 1343 // This is part of the magic to emulate layered windows with Aura
1346 // see the explanation elsewere when we set WS_EX_COMPOSITED style. 1344 // see the explanation elsewere when we set is_translucent_.
1347 MARGINS margins = {-1, -1, -1, -1}; 1345 MARGINS margins = {-1, -1, -1, -1};
1348 DwmExtendFrameIntoClientArea(hwnd(), &margins); 1346 DwmExtendFrameIntoClientArea(hwnd(), &margins);
1347
1348 ::SetProp(hwnd(), ui::kWindowTranslucent, reinterpret_cast<HANDLE>(1));
1349 } 1349 }
1350 1350
1351 fullscreen_handler_->set_hwnd(hwnd()); 1351 fullscreen_handler_->set_hwnd(hwnd());
1352 1352
1353 // This message initializes the window so that focus border are shown for 1353 // This message initializes the window so that focus border are shown for
1354 // windows. 1354 // windows.
1355 SendMessage(hwnd(), 1355 SendMessage(hwnd(),
1356 WM_CHANGEUISTATE, 1356 WM_CHANGEUISTATE,
1357 MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 1357 MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS),
1358 0); 1358 0);
(...skipping 21 matching lines...) Expand all
1380 base::Unretained(this)))); 1380 base::Unretained(this))));
1381 1381
1382 float scale_factor = display::win::ScreenWin::GetScaleFactorForHWND(hwnd()); 1382 float scale_factor = display::win::ScreenWin::GetScaleFactorForHWND(hwnd());
1383 dpi_ = display::win::GetDPIFromScalingFactor(scale_factor); 1383 dpi_ = display::win::GetDPIFromScalingFactor(scale_factor);
1384 1384
1385 // TODO(beng): move more of NWW::OnCreate here. 1385 // TODO(beng): move more of NWW::OnCreate here.
1386 return 0; 1386 return 0;
1387 } 1387 }
1388 1388
1389 void HWNDMessageHandler::OnDestroy() { 1389 void HWNDMessageHandler::OnDestroy() {
1390 ::RemoveProp(hwnd(), ui::kWindowTranslucent);
1390 windows_session_change_observer_.reset(nullptr); 1391 windows_session_change_observer_.reset(nullptr);
1391 delegate_->HandleDestroying(); 1392 delegate_->HandleDestroying();
1392 // If the window going away is a fullscreen window then remove its references 1393 // If the window going away is a fullscreen window then remove its references
1393 // from the full screen window map. 1394 // from the full screen window map.
1394 for (auto iter = fullscreen_monitor_map_.Get().begin(); 1395 for (auto iter = fullscreen_monitor_map_.Get().begin();
1395 iter != fullscreen_monitor_map_.Get().end(); 1396 iter != fullscreen_monitor_map_.Get().end();
1396 iter++) { 1397 iter++) {
1397 if (iter->second == this) { 1398 if (iter->second == this) {
1398 fullscreen_monitor_map_.Get().erase(iter); 1399 fullscreen_monitor_map_.Get().erase(iter);
1399 break; 1400 break;
(...skipping 1507 matching lines...) Expand 10 before | Expand all | Expand 10 after
2907 MONITORINFO monitor_info = {sizeof(monitor_info)}; 2908 MONITORINFO monitor_info = {sizeof(monitor_info)};
2908 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), 2909 GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY),
2909 &monitor_info); 2910 &monitor_info);
2910 gfx::Rect shrunk_rect(monitor_info.rcMonitor); 2911 gfx::Rect shrunk_rect(monitor_info.rcMonitor);
2911 shrunk_rect.set_height(shrunk_rect.height() - 1); 2912 shrunk_rect.set_height(shrunk_rect.height() - 1);
2912 background_fullscreen_hack_ = true; 2913 background_fullscreen_hack_ = true;
2913 SetBoundsInternal(shrunk_rect, false); 2914 SetBoundsInternal(shrunk_rect, false);
2914 } 2915 }
2915 2916
2916 } // namespace views 2917 } // namespace views
OLDNEW
« no previous file with comments | « 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