OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gfx/native_theme_win.h" | 5 #include "ui/gfx/native_theme_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <uxtheme.h> | 8 #include <uxtheme.h> |
9 #include <vsstyle.h> | 9 #include <vsstyle.h> |
10 #include <vssym32.h> | 10 #include <vssym32.h> |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 const ExtraParams& extra) const { | 119 const ExtraParams& extra) const { |
120 SIZE size; | 120 SIZE size; |
121 int part_id = GetWindowsPart(part, state, extra); | 121 int part_id = GetWindowsPart(part, state, extra); |
122 int state_id = GetWindowsState(part, state, extra); | 122 int state_id = GetWindowsState(part, state, extra); |
123 | 123 |
124 HDC hdc = GetDC(NULL); | 124 HDC hdc = GetDC(NULL); |
125 HRESULT hr = GetThemePartSize(GetThemeName(part), hdc, part_id, state_id, | 125 HRESULT hr = GetThemePartSize(GetThemeName(part), hdc, part_id, state_id, |
126 NULL, TS_TRUE, &size); | 126 NULL, TS_TRUE, &size); |
127 ReleaseDC(NULL, hdc); | 127 ReleaseDC(NULL, hdc); |
128 | 128 |
129 return SUCCEEDED(hr) ? Size(size.cx, size.cy) : Size(); | 129 if (FAILED(hr)) { |
| 130 // TODO(rogerta): For now, we need to support radio buttons and checkboxes |
| 131 // when theming is not enabled. Support for other parts can be added |
| 132 // if/when needed. |
| 133 switch (part) { |
| 134 case kCheckbox: |
| 135 case kRadio: |
| 136 // TODO(rogerta): I was not able to find any API to get the default |
| 137 // size of these controls, so determined these values empirically. |
| 138 size.cx = 13; |
| 139 size.cy = 13; |
| 140 break; |
| 141 default: |
| 142 size.cx = 0; |
| 143 size.cy = 0; |
| 144 break; |
| 145 } |
| 146 } |
| 147 |
| 148 return Size(size.cx, size.cy); |
130 } | 149 } |
131 | 150 |
132 void NativeThemeWin::PaintToNonPlatformCanvas(SkCanvas* canvas, | 151 void NativeThemeWin::PaintToNonPlatformCanvas(SkCanvas* canvas, |
133 Part part, | 152 Part part, |
134 State state, | 153 State state, |
135 const gfx::Rect& rect, | 154 const gfx::Rect& rect, |
136 const ExtraParams& extra) const { | 155 const ExtraParams& extra) const { |
137 // TODO(asvitkine): This path is pretty inefficient - for each paint operation | 156 // TODO(asvitkine): This path is pretty inefficient - for each paint operation |
138 // it creates a new offscreen bitmap Skia canvas. This can | 157 // it creates a new offscreen bitmap Skia canvas. This can |
139 // be sped up by doing it only once per part/state and | 158 // be sped up by doing it only once per part/state and |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 break; | 509 break; |
491 case kPressed: | 510 case kPressed: |
492 state_id = PBS_PRESSED; | 511 state_id = PBS_PRESSED; |
493 break; | 512 break; |
494 default: | 513 default: |
495 NOTREACHED() << "Invalid state: " << state; | 514 NOTREACHED() << "Invalid state: " << state; |
496 break; | 515 break; |
497 } | 516 } |
498 | 517 |
499 RECT rect_win = rect.ToRECT(); | 518 RECT rect_win = rect.ToRECT(); |
500 return PaintButton(hdc, BP_PUSHBUTTON, state_id, extra.classic_state, | 519 return PaintButton(hdc, state, BP_PUSHBUTTON, state_id, |
501 &rect_win); | 520 extra.classic_state | DFCS_BUTTONPUSH, &rect_win); |
502 } | 521 } |
503 | 522 |
504 HRESULT NativeThemeWin::PaintRadioButton(HDC hdc, | 523 HRESULT NativeThemeWin::PaintRadioButton(HDC hdc, |
505 Part part, | 524 Part part, |
506 State state, | 525 State state, |
507 const gfx::Rect& rect, | 526 const gfx::Rect& rect, |
508 const ButtonExtraParams& extra) const { | 527 const ButtonExtraParams& extra) const { |
509 int state_id; | 528 int state_id; |
510 switch(state) { | 529 switch(state) { |
511 case kDisabled: | 530 case kDisabled: |
512 state_id = extra.checked ? RBS_CHECKEDDISABLED : RBS_UNCHECKEDDISABLED; | 531 state_id = extra.checked ? RBS_CHECKEDDISABLED : RBS_UNCHECKEDDISABLED; |
513 break; | 532 break; |
514 case kHovered: | 533 case kHovered: |
515 state_id = extra.checked ? RBS_CHECKEDHOT : RBS_UNCHECKEDHOT; | 534 state_id = extra.checked ? RBS_CHECKEDHOT : RBS_UNCHECKEDHOT; |
516 break; | 535 break; |
517 case kNormal: | 536 case kNormal: |
518 state_id = extra.checked ? RBS_CHECKEDNORMAL : RBS_UNCHECKEDNORMAL; | 537 state_id = extra.checked ? RBS_CHECKEDNORMAL : RBS_UNCHECKEDNORMAL; |
519 break; | 538 break; |
520 case kPressed: | 539 case kPressed: |
521 state_id = extra.checked ? RBS_CHECKEDPRESSED : RBS_UNCHECKEDPRESSED; | 540 state_id = extra.checked ? RBS_CHECKEDPRESSED : RBS_UNCHECKEDPRESSED; |
522 break; | 541 break; |
523 default: | 542 default: |
524 NOTREACHED() << "Invalid state: " << state; | 543 NOTREACHED() << "Invalid state: " << state; |
525 break; | 544 break; |
526 } | 545 } |
527 | 546 |
528 RECT rect_win = rect.ToRECT(); | 547 RECT rect_win = rect.ToRECT(); |
529 return PaintButton(hdc, BP_RADIOBUTTON, state_id, extra.classic_state, | 548 return PaintButton(hdc, state, BP_RADIOBUTTON, state_id, |
530 &rect_win); | 549 extra.classic_state | DFCS_BUTTONRADIO, &rect_win); |
531 } | 550 } |
532 | 551 |
533 HRESULT NativeThemeWin::PaintCheckbox(HDC hdc, | 552 HRESULT NativeThemeWin::PaintCheckbox(HDC hdc, |
534 Part part, | 553 Part part, |
535 State state, | 554 State state, |
536 const gfx::Rect& rect, | 555 const gfx::Rect& rect, |
537 const ButtonExtraParams& extra) const { | 556 const ButtonExtraParams& extra) const { |
538 int state_id; | 557 int state_id; |
539 switch(state) { | 558 switch(state) { |
540 case kDisabled: | 559 case kDisabled: |
(...skipping 15 matching lines...) Expand all Loading... |
556 state_id = extra.checked ? CBS_CHECKEDPRESSED : | 575 state_id = extra.checked ? CBS_CHECKEDPRESSED : |
557 extra.indeterminate ? CBS_MIXEDPRESSED : | 576 extra.indeterminate ? CBS_MIXEDPRESSED : |
558 CBS_UNCHECKEDPRESSED; | 577 CBS_UNCHECKEDPRESSED; |
559 break; | 578 break; |
560 default: | 579 default: |
561 NOTREACHED() << "Invalid state: " << state; | 580 NOTREACHED() << "Invalid state: " << state; |
562 break; | 581 break; |
563 } | 582 } |
564 | 583 |
565 RECT rect_win = rect.ToRECT(); | 584 RECT rect_win = rect.ToRECT(); |
566 return PaintButton(hdc, BP_CHECKBOX, state_id, extra.classic_state, | 585 return PaintButton(hdc, state, BP_CHECKBOX, state_id, |
567 &rect_win); | 586 extra.classic_state | DFCS_BUTTONCHECK, &rect_win); |
568 } | 587 } |
569 | 588 |
570 HRESULT NativeThemeWin::PaintButton(HDC hdc, | 589 HRESULT NativeThemeWin::PaintButton(HDC hdc, |
| 590 State state, |
571 int part_id, | 591 int part_id, |
572 int state_id, | 592 int state_id, |
573 int classic_state, | 593 int classic_state, |
574 RECT* rect) const { | 594 RECT* rect) const { |
575 HANDLE handle = GetThemeHandle(BUTTON); | 595 HANDLE handle = GetThemeHandle(BUTTON); |
576 if (handle && draw_theme_) | 596 if (handle && draw_theme_) |
577 return draw_theme_(handle, hdc, part_id, state_id, rect, NULL); | 597 return draw_theme_(handle, hdc, part_id, state_id, rect, NULL); |
578 | 598 |
| 599 // Adjust classic_state based on State. |
| 600 switch(state) { |
| 601 case kDisabled: |
| 602 classic_state |= DFCS_INACTIVE; |
| 603 break; |
| 604 case kPressed: |
| 605 classic_state |= DFCS_PUSHED; |
| 606 break; |
| 607 case kNormal: |
| 608 case kHovered: |
| 609 break; |
| 610 default: |
| 611 NOTREACHED() << "Unknown state: " << state; |
| 612 break; |
| 613 } |
| 614 |
579 // Draw it manually. | 615 // Draw it manually. |
580 // All pressed states have both low bits set, and no other states do. | 616 // All pressed states have both low bits set, and no other states do. |
581 const bool focused = ((state_id & ETS_FOCUSED) == ETS_FOCUSED); | 617 const bool focused = ((state_id & ETS_FOCUSED) == ETS_FOCUSED); |
582 const bool pressed = ((state_id & PBS_PRESSED) == PBS_PRESSED); | 618 const bool pressed = ((state_id & PBS_PRESSED) == PBS_PRESSED); |
583 if ((BP_PUSHBUTTON == part_id) && (pressed || focused)) { | 619 if ((BP_PUSHBUTTON == part_id) && (pressed || focused)) { |
584 // BP_PUSHBUTTON has a focus rect drawn around the outer edge, and the | 620 // BP_PUSHBUTTON has a focus rect drawn around the outer edge, and the |
585 // button itself is shrunk by 1 pixel. | 621 // button itself is shrunk by 1 pixel. |
586 HBRUSH brush = GetSysColorBrush(COLOR_3DDKSHADOW); | 622 HBRUSH brush = GetSysColorBrush(COLOR_3DDKSHADOW); |
587 if (brush) { | 623 if (brush) { |
588 FrameRect(hdc, rect, brush); | 624 FrameRect(hdc, rect, brush); |
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1596 } | 1632 } |
1597 break; | 1633 break; |
1598 default: | 1634 default: |
1599 NOTREACHED() << "Invalid part: " << part; | 1635 NOTREACHED() << "Invalid part: " << part; |
1600 break; | 1636 break; |
1601 } | 1637 } |
1602 return state_id; | 1638 return state_id; |
1603 } | 1639 } |
1604 | 1640 |
1605 } // namespace gfx | 1641 } // namespace gfx |
OLD | NEW |