| 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/native_theme/native_theme_win.h" | 5 #include "ui/native_theme/native_theme_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <uxtheme.h> | 9 #include <uxtheme.h> |
| 10 #include <vsstyle.h> | 10 #include <vsstyle.h> |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 const gfx::Rect& rect, | 259 const gfx::Rect& rect, |
| 260 const ExtraParams& extra) const { | 260 const ExtraParams& extra) const { |
| 261 if (rect.IsEmpty()) | 261 if (rect.IsEmpty()) |
| 262 return; | 262 return; |
| 263 | 263 |
| 264 switch (part) { | 264 switch (part) { |
| 265 case kMenuPopupGutter: | 265 case kMenuPopupGutter: |
| 266 PaintMenuGutter(canvas, rect); | 266 PaintMenuGutter(canvas, rect); |
| 267 return; | 267 return; |
| 268 case kMenuPopupSeparator: | 268 case kMenuPopupSeparator: |
| 269 PaintMenuSeparator(canvas, *extra.menu_separator.paint_rect); | 269 PaintMenuSeparator(canvas, extra.menu_separator); |
| 270 return; | 270 return; |
| 271 case kMenuPopupBackground: | 271 case kMenuPopupBackground: |
| 272 PaintMenuBackground(canvas, rect); | 272 PaintMenuBackground(canvas, rect); |
| 273 return; | 273 return; |
| 274 case kMenuItemBackground: | 274 case kMenuItemBackground: |
| 275 CommonThemePaintMenuItemBackground(this, canvas, state, rect, | 275 CommonThemePaintMenuItemBackground(this, canvas, state, rect, |
| 276 extra.menu_item); | 276 extra.menu_item); |
| 277 return; | 277 return; |
| 278 default: | 278 default: |
| 279 PaintIndirect(canvas, part, state, rect, extra); | 279 PaintIndirect(canvas, part, state, rect, extra); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 UpdateSystemColors(); | 358 UpdateSystemColors(); |
| 359 is_using_high_contrast_valid_ = false; | 359 is_using_high_contrast_valid_ = false; |
| 360 NotifyObservers(); | 360 NotifyObservers(); |
| 361 } | 361 } |
| 362 | 362 |
| 363 void NativeThemeWin::UpdateSystemColors() { | 363 void NativeThemeWin::UpdateSystemColors() { |
| 364 for (int kSystemColor : kSystemColors) | 364 for (int kSystemColor : kSystemColors) |
| 365 system_colors_[kSystemColor] = color_utils::GetSysSkColor(kSystemColor); | 365 system_colors_[kSystemColor] = color_utils::GetSysSkColor(kSystemColor); |
| 366 } | 366 } |
| 367 | 367 |
| 368 void NativeThemeWin::PaintMenuSeparator(cc::PaintCanvas* canvas, | 368 void NativeThemeWin::PaintMenuSeparator( |
| 369 const gfx::Rect& rect) const { | 369 cc::PaintCanvas* canvas, |
| 370 const MenuSeparatorExtraParams& params) const { |
| 371 const gfx::RectF rect(*params.paint_rect); |
| 372 gfx::PointF start = rect.CenterPoint(); |
| 373 gfx::PointF end = start; |
| 374 if (params.type == ui::VERTICAL_SEPARATOR) { |
| 375 start.set_y(rect.y()); |
| 376 end.set_y(rect.bottom()); |
| 377 } else { |
| 378 start.set_x(rect.x()); |
| 379 end.set_x(rect.right()); |
| 380 } |
| 381 |
| 370 cc::PaintFlags flags; | 382 cc::PaintFlags flags; |
| 371 flags.setColor(GetSystemColor(NativeTheme::kColorId_MenuSeparatorColor)); | 383 flags.setColor(GetSystemColor(NativeTheme::kColorId_MenuSeparatorColor)); |
| 372 int position_y = rect.y() + rect.height() / 2; | 384 canvas->drawLine(start.x(), start.y(), end.x(), end.y(), flags); |
| 373 canvas->drawLine(rect.x(), position_y, rect.right(), position_y, flags); | |
| 374 } | 385 } |
| 375 | 386 |
| 376 void NativeThemeWin::PaintMenuGutter(cc::PaintCanvas* canvas, | 387 void NativeThemeWin::PaintMenuGutter(cc::PaintCanvas* canvas, |
| 377 const gfx::Rect& rect) const { | 388 const gfx::Rect& rect) const { |
| 378 cc::PaintFlags flags; | 389 cc::PaintFlags flags; |
| 379 flags.setColor(GetSystemColor(NativeTheme::kColorId_MenuSeparatorColor)); | 390 flags.setColor(GetSystemColor(NativeTheme::kColorId_MenuSeparatorColor)); |
| 380 int position_x = rect.x() + rect.width() / 2; | 391 int position_x = rect.x() + rect.width() / 2; |
| 381 canvas->drawLine(position_x, rect.y(), position_x, rect.bottom(), flags); | 392 canvas->drawLine(position_x, rect.y(), position_x, rect.bottom(), flags); |
| 382 } | 393 } |
| 383 | 394 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 406 return; | 417 return; |
| 407 case kMenuCheck: | 418 case kMenuCheck: |
| 408 PaintMenuCheck(hdc, state, rect, extra.menu_check); | 419 PaintMenuCheck(hdc, state, rect, extra.menu_check); |
| 409 return; | 420 return; |
| 410 case kMenuCheckBackground: | 421 case kMenuCheckBackground: |
| 411 PaintMenuCheckBackground(hdc, state, rect); | 422 PaintMenuCheckBackground(hdc, state, rect); |
| 412 return; | 423 return; |
| 413 case kMenuPopupArrow: | 424 case kMenuPopupArrow: |
| 414 PaintMenuArrow(hdc, state, rect, extra.menu_arrow); | 425 PaintMenuArrow(hdc, state, rect, extra.menu_arrow); |
| 415 return; | 426 return; |
| 416 case kMenuPopupBackground: | |
| 417 PaintMenuBackground(hdc, rect); | |
| 418 return; | |
| 419 case kMenuPopupGutter: | |
| 420 PaintMenuGutter(hdc, rect); | |
| 421 return; | |
| 422 case kMenuPopupSeparator: | |
| 423 PaintMenuSeparator(hdc, *extra.menu_separator.paint_rect); | |
| 424 return; | |
| 425 case kMenuItemBackground: | |
| 426 PaintMenuItemBackground(hdc, state, rect, extra.menu_item); | |
| 427 return; | |
| 428 case kProgressBar: | 427 case kProgressBar: |
| 429 PaintProgressBar(hdc, rect, extra.progress_bar); | 428 PaintProgressBar(hdc, rect, extra.progress_bar); |
| 430 return; | 429 return; |
| 431 case kPushButton: | 430 case kPushButton: |
| 432 PaintPushButton(hdc, part, state, rect, extra.button); | 431 PaintPushButton(hdc, part, state, rect, extra.button); |
| 433 return; | 432 return; |
| 434 case kRadio: | 433 case kRadio: |
| 435 PaintRadioButton(hdc, part, state, rect, extra.button); | 434 PaintRadioButton(hdc, part, state, rect, extra.button); |
| 436 return; | 435 return; |
| 437 case kScrollbarDownArrow: | 436 case kScrollbarDownArrow: |
| (...skipping 22 matching lines...) Expand all Loading... |
| 460 case kTextField: | 459 case kTextField: |
| 461 PaintTextField(hdc, part, state, rect, extra.text_field); | 460 PaintTextField(hdc, part, state, rect, extra.text_field); |
| 462 return; | 461 return; |
| 463 case kTrackbarThumb: | 462 case kTrackbarThumb: |
| 464 case kTrackbarTrack: | 463 case kTrackbarTrack: |
| 465 PaintTrackbar(destination_canvas, hdc, part, state, rect, extra.trackbar); | 464 PaintTrackbar(destination_canvas, hdc, part, state, rect, extra.trackbar); |
| 466 return; | 465 return; |
| 467 case kWindowResizeGripper: | 466 case kWindowResizeGripper: |
| 468 PaintWindowResizeGripper(hdc, rect); | 467 PaintWindowResizeGripper(hdc, rect); |
| 469 return; | 468 return; |
| 469 case kMenuPopupBackground: |
| 470 case kMenuPopupGutter: |
| 471 case kMenuPopupSeparator: |
| 472 case kMenuItemBackground: |
| 470 case kSliderTrack: | 473 case kSliderTrack: |
| 471 case kSliderThumb: | 474 case kSliderThumb: |
| 472 case kMaxPart: | 475 case kMaxPart: |
| 473 NOTREACHED(); | 476 NOTREACHED(); |
| 474 } | 477 } |
| 475 } | 478 } |
| 476 | 479 |
| 477 SkColor NativeThemeWin::GetSystemColor(ColorId color_id) const { | 480 SkColor NativeThemeWin::GetSystemColor(ColorId color_id) const { |
| 478 // TODO: Obtain the correct colors using GetSysColor. | 481 // TODO: Obtain the correct colors using GetSysColor. |
| 479 // Dialogs: | 482 // Dialogs: |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 // "4 / 13" is same as IE10 in classic theme. | 870 // "4 / 13" is same as IE10 in classic theme. |
| 868 int padding = (inner_rect.right - inner_rect.left) * 4 / 13; | 871 int padding = (inner_rect.right - inner_rect.left) * 4 / 13; |
| 869 InflateRect(&inner_rect, -padding, -padding); | 872 InflateRect(&inner_rect, -padding, -padding); |
| 870 int color_index = state == kDisabled ? COLOR_GRAYTEXT : COLOR_WINDOWTEXT; | 873 int color_index = state == kDisabled ? COLOR_GRAYTEXT : COLOR_WINDOWTEXT; |
| 871 FillRect(hdc, &inner_rect, GetSysColorBrush(color_index)); | 874 FillRect(hdc, &inner_rect, GetSysColorBrush(color_index)); |
| 872 } | 875 } |
| 873 | 876 |
| 874 return S_OK; | 877 return S_OK; |
| 875 } | 878 } |
| 876 | 879 |
| 877 HRESULT NativeThemeWin::PaintMenuSeparator(HDC hdc, | |
| 878 const gfx::Rect& rect) const { | |
| 879 RECT rect_win = rect.ToRECT(); | |
| 880 | |
| 881 HANDLE handle = GetThemeHandle(MENU); | |
| 882 if (handle && draw_theme_) { | |
| 883 // Delta is needed for non-classic to move separator up slightly. | |
| 884 --rect_win.top; | |
| 885 --rect_win.bottom; | |
| 886 return draw_theme_(handle, hdc, MENU_POPUPSEPARATOR, MPI_NORMAL, &rect_win, | |
| 887 NULL); | |
| 888 } | |
| 889 | |
| 890 DrawEdge(hdc, &rect_win, EDGE_ETCHED, BF_TOP); | |
| 891 return S_OK; | |
| 892 } | |
| 893 | |
| 894 HRESULT NativeThemeWin::PaintMenuGutter(HDC hdc, | |
| 895 const gfx::Rect& rect) const { | |
| 896 RECT rect_win = rect.ToRECT(); | |
| 897 HANDLE handle = GetThemeHandle(MENU); | |
| 898 return (handle && draw_theme_) ? | |
| 899 draw_theme_(handle, hdc, MENU_POPUPGUTTER, MPI_NORMAL, &rect_win, NULL) : | |
| 900 E_NOTIMPL; | |
| 901 } | |
| 902 | |
| 903 HRESULT NativeThemeWin::PaintMenuArrow( | 880 HRESULT NativeThemeWin::PaintMenuArrow( |
| 904 HDC hdc, | 881 HDC hdc, |
| 905 State state, | 882 State state, |
| 906 const gfx::Rect& rect, | 883 const gfx::Rect& rect, |
| 907 const MenuArrowExtraParams& extra) const { | 884 const MenuArrowExtraParams& extra) const { |
| 908 int state_id = MSM_NORMAL; | 885 int state_id = MSM_NORMAL; |
| 909 if (state == kDisabled) | 886 if (state == kDisabled) |
| 910 state_id = MSM_DISABLED; | 887 state_id = MSM_DISABLED; |
| 911 | 888 |
| 912 HANDLE handle = GetThemeHandle(MENU); | 889 HANDLE handle = GetThemeHandle(MENU); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 939 return result; | 916 return result; |
| 940 } | 917 } |
| 941 | 918 |
| 942 // For some reason, Windows uses the name DFCS_MENUARROWRIGHT to indicate a | 919 // For some reason, Windows uses the name DFCS_MENUARROWRIGHT to indicate a |
| 943 // left pointing arrow. This makes the following statement counterintuitive. | 920 // left pointing arrow. This makes the following statement counterintuitive. |
| 944 UINT pfc_state = extra.pointing_right ? DFCS_MENUARROW : DFCS_MENUARROWRIGHT; | 921 UINT pfc_state = extra.pointing_right ? DFCS_MENUARROW : DFCS_MENUARROWRIGHT; |
| 945 return PaintFrameControl(hdc, rect, DFC_MENU, pfc_state, extra.is_selected, | 922 return PaintFrameControl(hdc, rect, DFC_MENU, pfc_state, extra.is_selected, |
| 946 state); | 923 state); |
| 947 } | 924 } |
| 948 | 925 |
| 949 HRESULT NativeThemeWin::PaintMenuBackground(HDC hdc, | |
| 950 const gfx::Rect& rect) const { | |
| 951 HANDLE handle = GetThemeHandle(MENU); | |
| 952 RECT rect_win = rect.ToRECT(); | |
| 953 if (handle && draw_theme_) { | |
| 954 HRESULT result = draw_theme_(handle, hdc, MENU_POPUPBACKGROUND, 0, | |
| 955 &rect_win, NULL); | |
| 956 FrameRect(hdc, &rect_win, GetSysColorBrush(COLOR_3DSHADOW)); | |
| 957 return result; | |
| 958 } | |
| 959 | |
| 960 FillRect(hdc, &rect_win, GetSysColorBrush(COLOR_MENU)); | |
| 961 DrawEdge(hdc, &rect_win, EDGE_RAISED, BF_RECT); | |
| 962 return S_OK; | |
| 963 } | |
| 964 | |
| 965 HRESULT NativeThemeWin::PaintMenuCheck( | 926 HRESULT NativeThemeWin::PaintMenuCheck( |
| 966 HDC hdc, | 927 HDC hdc, |
| 967 State state, | 928 State state, |
| 968 const gfx::Rect& rect, | 929 const gfx::Rect& rect, |
| 969 const MenuCheckExtraParams& extra) const { | 930 const MenuCheckExtraParams& extra) const { |
| 970 HANDLE handle = GetThemeHandle(MENU); | 931 HANDLE handle = GetThemeHandle(MENU); |
| 971 if (handle && draw_theme_) { | 932 if (handle && draw_theme_) { |
| 972 const int state_id = extra.is_radio ? | 933 const int state_id = extra.is_radio ? |
| 973 ((state == kDisabled) ? MC_BULLETDISABLED : MC_BULLETNORMAL) : | 934 ((state == kDisabled) ? MC_BULLETDISABLED : MC_BULLETNORMAL) : |
| 974 ((state == kDisabled) ? MC_CHECKMARKDISABLED : MC_CHECKMARKNORMAL); | 935 ((state == kDisabled) ? MC_CHECKMARKDISABLED : MC_CHECKMARKNORMAL); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 987 HANDLE handle = GetThemeHandle(MENU); | 948 HANDLE handle = GetThemeHandle(MENU); |
| 988 if (!handle || !draw_theme_) | 949 if (!handle || !draw_theme_) |
| 989 return S_OK; // Nothing to do for background. | 950 return S_OK; // Nothing to do for background. |
| 990 | 951 |
| 991 int state_id = state == kDisabled ? MCB_DISABLED : MCB_NORMAL; | 952 int state_id = state == kDisabled ? MCB_DISABLED : MCB_NORMAL; |
| 992 RECT rect_win = rect.ToRECT(); | 953 RECT rect_win = rect.ToRECT(); |
| 993 return draw_theme_(handle, hdc, MENU_POPUPCHECKBACKGROUND, state_id, | 954 return draw_theme_(handle, hdc, MENU_POPUPCHECKBACKGROUND, state_id, |
| 994 &rect_win, NULL); | 955 &rect_win, NULL); |
| 995 } | 956 } |
| 996 | 957 |
| 997 HRESULT NativeThemeWin::PaintMenuItemBackground( | |
| 998 HDC hdc, | |
| 999 State state, | |
| 1000 const gfx::Rect& rect, | |
| 1001 const MenuItemExtraParams& extra) const { | |
| 1002 HANDLE handle = GetThemeHandle(MENU); | |
| 1003 RECT rect_win = rect.ToRECT(); | |
| 1004 int state_id = MPI_NORMAL; | |
| 1005 switch (state) { | |
| 1006 case kDisabled: | |
| 1007 state_id = extra.is_selected ? MPI_DISABLEDHOT : MPI_DISABLED; | |
| 1008 break; | |
| 1009 case kHovered: | |
| 1010 state_id = MPI_HOT; | |
| 1011 break; | |
| 1012 case kNormal: | |
| 1013 break; | |
| 1014 case kPressed: | |
| 1015 case kNumStates: | |
| 1016 NOTREACHED(); | |
| 1017 break; | |
| 1018 } | |
| 1019 | |
| 1020 if (handle && draw_theme_) | |
| 1021 return draw_theme_(handle, hdc, MENU_POPUPITEM, state_id, &rect_win, NULL); | |
| 1022 | |
| 1023 if (extra.is_selected) | |
| 1024 FillRect(hdc, &rect_win, GetSysColorBrush(COLOR_HIGHLIGHT)); | |
| 1025 return S_OK; | |
| 1026 } | |
| 1027 | |
| 1028 HRESULT NativeThemeWin::PaintPushButton(HDC hdc, | 958 HRESULT NativeThemeWin::PaintPushButton(HDC hdc, |
| 1029 Part part, | 959 Part part, |
| 1030 State state, | 960 State state, |
| 1031 const gfx::Rect& rect, | 961 const gfx::Rect& rect, |
| 1032 const ButtonExtraParams& extra) const { | 962 const ButtonExtraParams& extra) const { |
| 1033 int state_id = extra.is_default ? PBS_DEFAULTED : PBS_NORMAL; | 963 int state_id = extra.is_default ? PBS_DEFAULTED : PBS_NORMAL; |
| 1034 switch (state) { | 964 switch (state) { |
| 1035 case kDisabled: | 965 case kDisabled: |
| 1036 state_id = PBS_DISABLED; | 966 state_id = PBS_DISABLED; |
| 1037 break; | 967 break; |
| (...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2108 break; | 2038 break; |
| 2109 case LAST: | 2039 case LAST: |
| 2110 NOTREACHED(); | 2040 NOTREACHED(); |
| 2111 break; | 2041 break; |
| 2112 } | 2042 } |
| 2113 theme_handles_[theme_name] = handle; | 2043 theme_handles_[theme_name] = handle; |
| 2114 return handle; | 2044 return handle; |
| 2115 } | 2045 } |
| 2116 | 2046 |
| 2117 } // namespace ui | 2047 } // namespace ui |
| OLD | NEW |