| OLD | NEW |
| 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/widget/native_widget_win.h" | 5 #include "ui/views/widget/native_widget_win.h" |
| 6 | 6 |
| 7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" | 21 #include "ui/base/dragdrop/os_exchange_data_provider_win.h" |
| 22 #include "ui/base/keycodes/keyboard_code_conversion_win.h" | 22 #include "ui/base/keycodes/keyboard_code_conversion_win.h" |
| 23 #include "ui/base/l10n/l10n_util_win.h" | 23 #include "ui/base/l10n/l10n_util_win.h" |
| 24 #include "ui/base/theme_provider.h" | 24 #include "ui/base/theme_provider.h" |
| 25 #include "ui/base/view_prop.h" | 25 #include "ui/base/view_prop.h" |
| 26 #include "ui/base/win/hwnd_util.h" | 26 #include "ui/base/win/hwnd_util.h" |
| 27 #include "ui/base/win/mouse_wheel_util.h" | 27 #include "ui/base/win/mouse_wheel_util.h" |
| 28 #include "ui/gfx/canvas.h" | 28 #include "ui/gfx/canvas.h" |
| 29 #include "ui/gfx/canvas_paint.h" | 29 #include "ui/gfx/canvas_paint.h" |
| 30 #include "ui/gfx/canvas_skia_paint.h" | 30 #include "ui/gfx/canvas_skia_paint.h" |
| 31 #include "ui/gfx/gdi_util.h" |
| 31 #include "ui/gfx/icon_util.h" | 32 #include "ui/gfx/icon_util.h" |
| 32 #include "ui/base/native_theme/native_theme_win.h" | 33 #include "ui/base/native_theme/native_theme_win.h" |
| 33 #include "ui/gfx/path.h" | 34 #include "ui/gfx/path.h" |
| 34 #include "ui/gfx/screen.h" | 35 #include "ui/gfx/screen.h" |
| 35 #include "ui/views/accessibility/native_view_accessibility_win.h" | 36 #include "ui/views/accessibility/native_view_accessibility_win.h" |
| 36 #include "ui/views/controls/native_control_win.h" | 37 #include "ui/views/controls/native_control_win.h" |
| 37 #include "ui/views/controls/textfield/native_textfield_views.h" | 38 #include "ui/views/controls/textfield/native_textfield_views.h" |
| 38 #include "ui/views/drag_utils.h" | 39 #include "ui/views/drag_utils.h" |
| 39 #include "ui/views/focus/accelerator_handler.h" | 40 #include "ui/views/focus/accelerator_handler.h" |
| 40 #include "ui/views/focus/view_storage.h" | 41 #include "ui/views/focus/view_storage.h" |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 BOOL CALLBACK FindOwnedWindowsCallback(HWND hwnd, LPARAM param) { | 324 BOOL CALLBACK FindOwnedWindowsCallback(HWND hwnd, LPARAM param) { |
| 324 FindOwnedWindowsData* data = reinterpret_cast<FindOwnedWindowsData*>(param); | 325 FindOwnedWindowsData* data = reinterpret_cast<FindOwnedWindowsData*>(param); |
| 325 if (GetWindow(hwnd, GW_OWNER) == data->window) { | 326 if (GetWindow(hwnd, GW_OWNER) == data->window) { |
| 326 Widget* widget = Widget::GetWidgetForNativeView(hwnd); | 327 Widget* widget = Widget::GetWidgetForNativeView(hwnd); |
| 327 if (widget) | 328 if (widget) |
| 328 data->owned_widgets.push_back(widget); | 329 data->owned_widgets.push_back(widget); |
| 329 } | 330 } |
| 330 return TRUE; | 331 return TRUE; |
| 331 } | 332 } |
| 332 | 333 |
| 334 HBITMAP GetNativeBitmapFromSkBitmap(const SkBitmap& bitmap) { |
| 335 int width = bitmap.width(); |
| 336 int height = bitmap.height(); |
| 337 |
| 338 BITMAPV4HEADER native_bitmap_header; |
| 339 gfx::CreateBitmapV4Header(width, height, &native_bitmap_header); |
| 340 |
| 341 HDC dc = ::GetDC(NULL); |
| 342 void* bits; |
| 343 HBITMAP native_bitmap = ::CreateDIBSection(dc, |
| 344 reinterpret_cast<BITMAPINFO*>(&native_bitmap_header), |
| 345 DIB_RGB_COLORS, |
| 346 &bits, |
| 347 NULL, |
| 348 0); |
| 349 DCHECK(native_bitmap); |
| 350 ::ReleaseDC(NULL, dc); |
| 351 bitmap.copyPixelsTo(bits, width * height * 4, width * 4); |
| 352 return native_bitmap; |
| 353 } |
| 354 |
| 333 } // namespace | 355 } // namespace |
| 334 | 356 |
| 335 // static | 357 // static |
| 336 bool NativeWidgetWin::screen_reader_active_ = false; | 358 bool NativeWidgetWin::screen_reader_active_ = false; |
| 337 | 359 |
| 338 // A scoping class that prevents a window from being able to redraw in response | 360 // A scoping class that prevents a window from being able to redraw in response |
| 339 // to invalidations that may occur within it for the lifetime of the object. | 361 // to invalidations that may occur within it for the lifetime of the object. |
| 340 // | 362 // |
| 341 // Why would we want such a thing? Well, it turns out Windows has some | 363 // Why would we want such a thing? Well, it turns out Windows has some |
| 342 // "unorthodox" behavior when it comes to painting its non-client areas. | 364 // "unorthodox" behavior when it comes to painting its non-client areas. |
| (...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 // For some reason, we need to hide the window while we're changing the frame | 1382 // For some reason, we need to hide the window while we're changing the frame |
| 1361 // type only when we're changing it in response to WM_DWMCOMPOSITIONCHANGED. | 1383 // type only when we're changing it in response to WM_DWMCOMPOSITIONCHANGED. |
| 1362 // If we don't, the client area will be filled with black. I'm suspecting | 1384 // If we don't, the client area will be filled with black. I'm suspecting |
| 1363 // something skia-ey. | 1385 // something skia-ey. |
| 1364 // Frame type toggling caused by the user (e.g. switching theme) doesn't seem | 1386 // Frame type toggling caused by the user (e.g. switching theme) doesn't seem |
| 1365 // to have this requirement. | 1387 // to have this requirement. |
| 1366 FrameTypeChanged(); | 1388 FrameTypeChanged(); |
| 1367 return 0; | 1389 return 0; |
| 1368 } | 1390 } |
| 1369 | 1391 |
| 1392 LRESULT NativeWidgetWin::OnDwmSendIconicThumbnail(UINT msg, |
| 1393 WPARAM w_param, |
| 1394 LPARAM l_param) { |
| 1395 if (!GetWidget()->non_client_view()) { |
| 1396 SetMsgHandled(FALSE); |
| 1397 return 0; |
| 1398 } |
| 1399 |
| 1400 gfx::Size size(HIWORD(l_param), LOWORD(l_param)); |
| 1401 SkBitmap preview_bitmap = |
| 1402 GetWidget()->widget_delegate()->GetPreviewImage(size, false); |
| 1403 if (preview_bitmap.empty()) { |
| 1404 SetMsgHandled(FALSE); |
| 1405 return 0; |
| 1406 } |
| 1407 |
| 1408 HBITMAP native_bitmap = GetNativeBitmapFromSkBitmap(preview_bitmap); |
| 1409 ::DwmSetIconicThumbnail(hwnd(), native_bitmap, 0); |
| 1410 ::DeleteObject(native_bitmap); |
| 1411 return 0; |
| 1412 } |
| 1413 |
| 1414 LRESULT NativeWidgetWin::OnDwmSendIconicLivePreviewBitmap(UINT msg, |
| 1415 WPARAM w_param, |
| 1416 LPARAM l_param) { |
| 1417 if (!GetWidget()->non_client_view()) { |
| 1418 SetMsgHandled(FALSE); |
| 1419 return 0; |
| 1420 } |
| 1421 |
| 1422 gfx::Rect bounds = GetWindowScreenBounds(); |
| 1423 SkBitmap preview_bitmap = |
| 1424 GetWidget()->widget_delegate()->GetPreviewImage(bounds.size(), true); |
| 1425 if (preview_bitmap.empty()) { |
| 1426 SetMsgHandled(FALSE); |
| 1427 return 0; |
| 1428 } |
| 1429 |
| 1430 HBITMAP native_bitmap = GetNativeBitmapFromSkBitmap(preview_bitmap); |
| 1431 ::DwmSetIconicLivePreviewBitmap(hwnd(), native_bitmap, NULL, 0); |
| 1432 ::DeleteObject(native_bitmap); |
| 1433 return 0; |
| 1434 } |
| 1435 |
| 1370 void NativeWidgetWin::OnEndSession(BOOL ending, UINT logoff) { | 1436 void NativeWidgetWin::OnEndSession(BOOL ending, UINT logoff) { |
| 1371 SetMsgHandled(FALSE); | 1437 SetMsgHandled(FALSE); |
| 1372 } | 1438 } |
| 1373 | 1439 |
| 1374 void NativeWidgetWin::OnEnterSizeMove() { | 1440 void NativeWidgetWin::OnEnterSizeMove() { |
| 1375 delegate_->OnNativeWidgetBeginUserBoundsChange(); | 1441 delegate_->OnNativeWidgetBeginUserBoundsChange(); |
| 1376 SetMsgHandled(FALSE); | 1442 SetMsgHandled(FALSE); |
| 1377 } | 1443 } |
| 1378 | 1444 |
| 1379 LRESULT NativeWidgetWin::OnEraseBkgnd(HDC dc) { | 1445 LRESULT NativeWidgetWin::OnEraseBkgnd(HDC dc) { |
| (...skipping 1297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2677 return (GetKeyState(VK_LBUTTON) & 0x80) || | 2743 return (GetKeyState(VK_LBUTTON) & 0x80) || |
| 2678 (GetKeyState(VK_RBUTTON) & 0x80) || | 2744 (GetKeyState(VK_RBUTTON) & 0x80) || |
| 2679 (GetKeyState(VK_MBUTTON) & 0x80) || | 2745 (GetKeyState(VK_MBUTTON) & 0x80) || |
| 2680 (GetKeyState(VK_XBUTTON1) & 0x80) || | 2746 (GetKeyState(VK_XBUTTON1) & 0x80) || |
| 2681 (GetKeyState(VK_XBUTTON2) & 0x80); | 2747 (GetKeyState(VK_XBUTTON2) & 0x80); |
| 2682 } | 2748 } |
| 2683 | 2749 |
| 2684 } // namespace internal | 2750 } // namespace internal |
| 2685 | 2751 |
| 2686 } // namespace views | 2752 } // namespace views |
| OLD | NEW |