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

Side by Side Diff: views/controls/tree/tree_view.cc

Issue 6879013: skia::PlatformCanvas is being deprecated. Going forward we will use gfx::Canvas wherever we need ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
« no previous file with comments | « views/controls/textfield/native_textfield_views.cc ('k') | views/drag_utils.cc » ('j') | 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) 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 "views/controls/tree/tree_view.h" 5 #include "views/controls/tree/tree_view.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/stl_util-inl.h" 11 #include "base/stl_util-inl.h"
12 #include "base/win/win_util.h" 12 #include "base/win/win_util.h"
13 #include "grit/app_resources.h" 13 #include "grit/app_resources.h"
14 #include "ui/base/accessibility/accessible_view_state.h" 14 #include "ui/base/accessibility/accessible_view_state.h"
15 #include "ui/base/keycodes/keyboard_codes.h" 15 #include "ui/base/keycodes/keyboard_codes.h"
16 #include "ui/base/keycodes/keyboard_code_conversion_win.h" 16 #include "ui/base/keycodes/keyboard_code_conversion_win.h"
17 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/base/win/hwnd_util.h" 18 #include "ui/base/win/hwnd_util.h"
19 #include "ui/base/l10n/l10n_util_win.h" 19 #include "ui/base/l10n/l10n_util_win.h"
20 #include "ui/gfx/canvas_skia.h" 20 #include "ui/gfx/canvas_skia.h"
21 #include "ui/gfx/canvas_skia_paint.h"
22 #include "ui/gfx/favicon_size.h" 21 #include "ui/gfx/favicon_size.h"
23 #include "ui/gfx/icon_util.h" 22 #include "ui/gfx/icon_util.h"
24 #include "ui/gfx/point.h" 23 #include "ui/gfx/point.h"
25 #include "views/focus/focus_manager.h" 24 #include "views/focus/focus_manager.h"
26 #include "views/widget/widget.h" 25 #include "views/widget/widget.h"
27 26
28 using ui::TreeModel; 27 using ui::TreeModel;
29 using ui::TreeModelNode; 28 using ui::TreeModelNode;
30 29
31 namespace views { 30 namespace views {
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 ImageList_AddIcon(image_list, h_opened_icon); 692 ImageList_AddIcon(image_list, h_opened_icon);
694 DestroyIcon(h_closed_icon); 693 DestroyIcon(h_closed_icon);
695 DestroyIcon(h_opened_icon); 694 DestroyIcon(h_opened_icon);
696 for (size_t i = 0; i < model_images.size(); ++i) { 695 for (size_t i = 0; i < model_images.size(); ++i) {
697 HICON model_icon; 696 HICON model_icon;
698 697
699 // Need to resize the provided icons to be the same size as 698 // Need to resize the provided icons to be the same size as
700 // IDR_FOLDER_CLOSED if they aren't already. 699 // IDR_FOLDER_CLOSED if they aren't already.
701 if (model_images[i].width() != width || 700 if (model_images[i].width() != width ||
702 model_images[i].height() != height) { 701 model_images[i].height() != height) {
703 gfx::CanvasSkia canvas(width, height, false); 702 gfx::CanvasSkia canvas;
703 canvas.Init(width, height, false);
704 // Make the background completely transparent. 704 // Make the background completely transparent.
705 canvas.drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); 705 canvas.skia_canvas()->drawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
706 706
707 // Draw our icons into this canvas. 707 // Draw our icons into this canvas.
708 int height_offset = (height - model_images[i].height()) / 2; 708 int height_offset = (height - model_images[i].height()) / 2;
709 int width_offset = (width - model_images[i].width()) / 2; 709 int width_offset = (width - model_images[i].width()) / 2;
710 canvas.DrawBitmapInt(model_images[i], width_offset, height_offset); 710 canvas.DrawBitmapInt(model_images[i], width_offset, height_offset);
711 model_icon = IconUtil::CreateHICONFromSkBitmap(canvas.ExtractBitmap()); 711 model_icon = IconUtil::CreateHICONFromSkBitmap(canvas.ExtractBitmap());
712 } else { 712 } else {
713 model_icon = IconUtil::CreateHICONFromSkBitmap(model_images[i]); 713 model_icon = IconUtil::CreateHICONFromSkBitmap(model_images[i]);
714 } 714 }
715 ImageList_AddIcon(image_list, model_icon); 715 ImageList_AddIcon(image_list, model_icon);
(...skipping 28 matching lines...) Expand all
744 744
745 // We handle the messages WM_ERASEBKGND and WM_PAINT such that we paint into 745 // We handle the messages WM_ERASEBKGND and WM_PAINT such that we paint into
746 // a DIB first and then perform a BitBlt from the DIB into the underlying 746 // a DIB first and then perform a BitBlt from the DIB into the underlying
747 // window's DC. This double buffering code prevents the tree view from 747 // window's DC. This double buffering code prevents the tree view from
748 // flickering during resize. 748 // flickering during resize.
749 switch (message) { 749 switch (message) {
750 case WM_ERASEBKGND: 750 case WM_ERASEBKGND:
751 return 1; 751 return 1;
752 752
753 case WM_PAINT: { 753 case WM_PAINT: {
754 gfx::CanvasSkiaPaint canvas(window); 754 PAINTSTRUCT ps = {0};
755 if (canvas.isEmpty()) 755 HDC window_dc = BeginPaint(window, &ps);
756
757 int width = ps.rcPaint.right - ps.rcPaint.left;
758 int height = ps.rcPaint.bottom - ps.rcPaint.top;
759 if ((width == 0) || (height == 0))
756 return 0; 760 return 0;
757 761
758 HDC dc = canvas.beginPlatformPaint(); 762 // Create a bitmap to draw on.
763 HDC bitmap_dc = CreateCompatibleDC(window_dc);
764 HBITMAP bitmap = CreateCompatibleBitmap(window_dc, width, height);
765 HGDIOBJ default_obj = SelectObject(bitmap_dc, bitmap);
759 if (base::i18n::IsRTL()) { 766 if (base::i18n::IsRTL()) {
767 // TODO(alokp): May not need this hack anymore since we are creating
768 // a compatible bitmap device context.
769
760 // gfx::CanvasSkia ends up configuring the DC with a mode of 770 // gfx::CanvasSkia ends up configuring the DC with a mode of
761 // GM_ADVANCED. For some reason a graphics mode of ADVANCED triggers 771 // GM_ADVANCED. For some reason a graphics mode of ADVANCED triggers
762 // all the text to be mirrored when RTL. Set the mode back to COMPATIBLE 772 // all the text to be mirrored when RTL. Set the mode back to COMPATIBLE
763 // and explicitly set the layout. Additionally SetWorldTransform and 773 // and explicitly set the layout. Additionally SetWorldTransform and
764 // COMPATIBLE don't play nicely together. We need to use 774 // COMPATIBLE don't play nicely together. We need to use
765 // SetViewportOrgEx when using a mode of COMPATIBLE. 775 // SetViewportOrgEx when using a mode of COMPATIBLE.
766 // 776 //
767 // Reset the transform to the identify transform. Even though 777 // Reset the transform to the identify transform. Even though
768 // SetWorldTransform and COMPATIBLE don't play nicely, bits of the 778 // SetWorldTransform and COMPATIBLE don't play nicely, bits of the
769 // transform still carry over when we set the mode. 779 // transform still carry over when we set the mode.
770 XFORM xform = {0}; 780 XFORM xform = {0};
771 xform.eM11 = xform.eM22 = 1; 781 xform.eM11 = xform.eM22 = 1;
772 SetWorldTransform(dc, &xform); 782 SetWorldTransform(bitmap_dc, &xform);
773 783
774 // Set the mode and layout. 784 // Set the mode and layout.
775 SetGraphicsMode(dc, GM_COMPATIBLE); 785 SetGraphicsMode(bitmap_dc, GM_COMPATIBLE);
776 SetLayout(dc, LAYOUT_RTL); 786 SetLayout(bitmap_dc, LAYOUT_RTL);
777 787
778 // Transform the viewport such that the origin of the dc is that of 788 // Transform the viewport such that the origin of the dc is that of
779 // the dirty region. This way when we invoke WM_PRINTCLIENT tree-view 789 // the dirty region. This way when we invoke WM_PRINTCLIENT tree-view
780 // draws the dirty region at the origin of the DC so that when we 790 // draws the dirty region at the origin of the DC so that when we
781 // copy the bits everything lines up nicely. Without this we end up 791 // copy the bits everything lines up nicely. Without this we end up
782 // copying the upper-left corner to the redraw region. 792 // copying the upper-left corner to the redraw region.
783 SetViewportOrgEx(dc, -canvas.paintStruct().rcPaint.left, 793 SetViewportOrgEx(bitmap_dc, -ps.rcPaint.left, -ps.rcPaint.top, NULL);
784 -canvas.paintStruct().rcPaint.top, NULL);
785 } 794 }
786 SendMessage(window, WM_PRINTCLIENT, reinterpret_cast<WPARAM>(dc), 0); 795
796 SendMessage(window, WM_PRINTCLIENT,
797 reinterpret_cast<WPARAM>(bitmap_dc), 0);
798
787 if (base::i18n::IsRTL()) { 799 if (base::i18n::IsRTL()) {
788 // Reset the origin of the dc back to 0. This way when we copy the bits 800 // Reset the origin of the dc back to 0. This way when we copy the bits
789 // over we copy the right bits. 801 // over we copy the right bits.
790 SetViewportOrgEx(dc, 0, 0, NULL); 802 SetViewportOrgEx(bitmap_dc, 0, 0, NULL);
791 } 803 }
792 canvas.endPlatformPaint(); 804
805 // Copy the bitmap to window.
806 BitBlt(window_dc, ps.rcPaint.left, ps.rcPaint.top, width, height,
807 bitmap_dc, 0, 0, SRCCOPY);
808
809 // Cleanup.
810 SelectObject(bitmap_dc, default_obj);
811 DeleteDC(bitmap_dc);
812 DeleteObject(bitmap);
813 EndPaint(window, &ps);
793 return 0; 814 return 0;
794 } 815 }
795 816
796 case WM_RBUTTONDOWN: 817 case WM_RBUTTONDOWN:
797 if (tree->select_on_right_mouse_down_) { 818 if (tree->select_on_right_mouse_down_) {
798 TVHITTESTINFO hit_info; 819 TVHITTESTINFO hit_info;
799 hit_info.pt = gfx::Point(l_param).ToPOINT(); 820 hit_info.pt = gfx::Point(l_param).ToPOINT();
800 HTREEITEM hit_item = TreeView_HitTest(window, &hit_info); 821 HTREEITEM hit_item = TreeView_HitTest(window, &hit_info);
801 if (hit_item && (hit_info.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT | 822 if (hit_item && (hit_info.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT |
802 TVHT_ONITEMINDENT)) != 0) 823 TVHT_ONITEMINDENT)) != 0)
803 TreeView_SelectItem(tree->tree_view_, hit_item); 824 TreeView_SelectItem(tree->tree_view_, hit_item);
804 } 825 }
805 // Fall through and let the default handler process as well. 826 // Fall through and let the default handler process as well.
806 break; 827 break;
807 } 828 }
808 WNDPROC handler = tree->original_handler_; 829 WNDPROC handler = tree->original_handler_;
809 DCHECK(handler); 830 DCHECK(handler);
810 return CallWindowProc(handler, window, message, w_param, l_param); 831 return CallWindowProc(handler, window, message, w_param, l_param);
811 } 832 }
812 833
813 } // namespace views 834 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/textfield/native_textfield_views.cc ('k') | views/drag_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698