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

Side by Side Diff: views/controls/menu/chrome_menu.cc

Issue 113443: ChromeCanvas->gfx::Canvas (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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/menu/chrome_menu.h ('k') | views/controls/menu/menu_win.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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/menu/chrome_menu.h" 5 #include "views/controls/menu/chrome_menu.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <uxtheme.h> 8 #include <uxtheme.h>
9 #include <Vssym32.h> 9 #include <Vssym32.h>
10 10
11 #include "app/gfx/chrome_canvas.h" 11 #include "app/gfx/canvas.h"
12 #include "app/gfx/color_utils.h" 12 #include "app/gfx/color_utils.h"
13 #include "app/l10n_util.h" 13 #include "app/l10n_util.h"
14 #include "app/l10n_util_win.h" 14 #include "app/l10n_util_win.h"
15 #include "app/os_exchange_data.h" 15 #include "app/os_exchange_data.h"
16 #include "base/base_drag_source.h" 16 #include "base/base_drag_source.h"
17 #include "base/gfx/native_theme.h" 17 #include "base/gfx/native_theme.h"
18 #include "base/message_loop.h" 18 #include "base/message_loop.h"
19 #include "base/task.h" 19 #include "base/task.h"
20 #include "base/timer.h" 20 #include "base/timer.h"
21 #include "base/win_util.h" 21 #include "base/win_util.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 328
329 virtual void OnDragExited() { 329 virtual void OnDragExited() {
330 DCHECK(host_->GetMenuItem()->GetMenuController()); 330 DCHECK(host_->GetMenuItem()->GetMenuController());
331 host_->GetMenuItem()->GetMenuController()->OnDragExitedScrollButton(host_); 331 host_->GetMenuItem()->GetMenuController()->OnDragExitedScrollButton(host_);
332 } 332 }
333 333
334 virtual int OnPerformDrop(const DropTargetEvent& event) { 334 virtual int OnPerformDrop(const DropTargetEvent& event) {
335 return DragDropTypes::DRAG_NONE; 335 return DragDropTypes::DRAG_NONE;
336 } 336 }
337 337
338 virtual void Paint(ChromeCanvas* canvas) { 338 virtual void Paint(gfx::Canvas* canvas) {
339 HDC dc = canvas->beginPlatformPaint(); 339 HDC dc = canvas->beginPlatformPaint();
340 340
341 // The background. 341 // The background.
342 RECT item_bounds = { 0, 0, width(), height() }; 342 RECT item_bounds = { 0, 0, width(), height() };
343 NativeTheme::instance()->PaintMenuItemBackground( 343 NativeTheme::instance()->PaintMenuItemBackground(
344 NativeTheme::MENU, dc, MENU_POPUPITEM, MPI_NORMAL, false, 344 NativeTheme::MENU, dc, MENU_POPUPITEM, MPI_NORMAL, false,
345 &item_bounds); 345 &item_bounds);
346 346
347 // Then the arrow. 347 // Then the arrow.
348 int x = width() / 2; 348 int x = width() / 2;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 AddChildView(scroll_down_button_); 423 AddChildView(scroll_down_button_);
424 424
425 scroll_view_ = new MenuScrollView(content_view); 425 scroll_view_ = new MenuScrollView(content_view);
426 AddChildView(scroll_view_); 426 AddChildView(scroll_view_);
427 427
428 set_border(Border::CreateEmptyBorder( 428 set_border(Border::CreateEmptyBorder(
429 kSubmenuBorderSize, kSubmenuBorderSize, 429 kSubmenuBorderSize, kSubmenuBorderSize,
430 kSubmenuBorderSize, kSubmenuBorderSize)); 430 kSubmenuBorderSize, kSubmenuBorderSize));
431 } 431 }
432 432
433 virtual void Paint(ChromeCanvas* canvas) { 433 virtual void Paint(gfx::Canvas* canvas) {
434 HDC dc = canvas->beginPlatformPaint(); 434 HDC dc = canvas->beginPlatformPaint();
435 CRect bounds(0, 0, width(), height()); 435 CRect bounds(0, 0, width(), height());
436 NativeTheme::instance()->PaintMenuBackground( 436 NativeTheme::instance()->PaintMenuBackground(
437 NativeTheme::MENU, dc, MENU_POPUPBACKGROUND, 0, &bounds); 437 NativeTheme::MENU, dc, MENU_POPUPBACKGROUND, 0, &bounds);
438 canvas->endPlatformPaint(); 438 canvas->endPlatformPaint();
439 } 439 }
440 440
441 View* scroll_down_button() { return scroll_down_button_; } 441 View* scroll_down_button() { return scroll_down_button_; }
442 442
443 View* scroll_up_button() { return scroll_up_button_; } 443 View* scroll_up_button() { return scroll_up_button_; }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 496
497 // MenuSeparator --------------------------------------------------------------- 497 // MenuSeparator ---------------------------------------------------------------
498 498
499 // Renders a separator. 499 // Renders a separator.
500 500
501 class MenuSeparator : public View { 501 class MenuSeparator : public View {
502 public: 502 public:
503 MenuSeparator() { 503 MenuSeparator() {
504 } 504 }
505 505
506 void Paint(ChromeCanvas* canvas) { 506 void Paint(gfx::Canvas* canvas) {
507 // The gutter is rendered before the background. 507 // The gutter is rendered before the background.
508 int start_x = 0; 508 int start_x = 0;
509 int start_y = height() / 3; 509 int start_y = height() / 3;
510 HDC dc = canvas->beginPlatformPaint(); 510 HDC dc = canvas->beginPlatformPaint();
511 if (render_gutter) { 511 if (render_gutter) {
512 // If render_gutter is true, we're on Vista and need to render the 512 // If render_gutter is true, we're on Vista and need to render the
513 // gutter, then indent the separator from the gutter. 513 // gutter, then indent the separator from the gutter.
514 RECT gutter_bounds = { label_start - kGutterToLabel - gutter_width, 0, 0, 514 RECT gutter_bounds = { label_start - kGutterToLabel - gutter_width, 0, 0,
515 height() }; 515 height() };
516 gutter_bounds.right = gutter_bounds.left + gutter_width; 516 gutter_bounds.right = gutter_bounds.left + gutter_width;
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 } 866 }
867 gfx::Insets insets = GetInsets(); 867 gfx::Insets insets = GetInsets();
868 return gfx::Size(max_width + insets.width(), height + insets.height()); 868 return gfx::Size(max_width + insets.width(), height + insets.height());
869 } 869 }
870 870
871 void SubmenuView::DidChangeBounds(const gfx::Rect& previous, 871 void SubmenuView::DidChangeBounds(const gfx::Rect& previous,
872 const gfx::Rect& current) { 872 const gfx::Rect& current) {
873 SchedulePaint(); 873 SchedulePaint();
874 } 874 }
875 875
876 void SubmenuView::PaintChildren(ChromeCanvas* canvas) { 876 void SubmenuView::PaintChildren(gfx::Canvas* canvas) {
877 View::PaintChildren(canvas); 877 View::PaintChildren(canvas);
878 878
879 if (drop_item_ && drop_position_ != MenuDelegate::DROP_ON) 879 if (drop_item_ && drop_position_ != MenuDelegate::DROP_ON)
880 PaintDropIndicator(canvas, drop_item_, drop_position_); 880 PaintDropIndicator(canvas, drop_item_, drop_position_);
881 } 881 }
882 882
883 bool SubmenuView::CanDrop(const OSExchangeData& data) { 883 bool SubmenuView::CanDrop(const OSExchangeData& data) {
884 DCHECK(GetMenuItem()->GetMenuController()); 884 DCHECK(GetMenuItem()->GetMenuController());
885 return GetMenuItem()->GetMenuController()->CanDrop(this, data); 885 return GetMenuItem()->GetMenuController()->CanDrop(this, data);
886 } 886 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 1024
1025 MenuScrollViewContainer* SubmenuView::GetScrollViewContainer() { 1025 MenuScrollViewContainer* SubmenuView::GetScrollViewContainer() {
1026 if (!scroll_view_container_) { 1026 if (!scroll_view_container_) {
1027 scroll_view_container_ = new MenuScrollViewContainer(this); 1027 scroll_view_container_ = new MenuScrollViewContainer(this);
1028 // Otherwise MenuHost would delete us. 1028 // Otherwise MenuHost would delete us.
1029 scroll_view_container_->SetParentOwned(false); 1029 scroll_view_container_->SetParentOwned(false);
1030 } 1030 }
1031 return scroll_view_container_; 1031 return scroll_view_container_;
1032 } 1032 }
1033 1033
1034 void SubmenuView::PaintDropIndicator(ChromeCanvas* canvas, 1034 void SubmenuView::PaintDropIndicator(gfx::Canvas* canvas,
1035 MenuItemView* item, 1035 MenuItemView* item,
1036 MenuDelegate::DropPosition position) { 1036 MenuDelegate::DropPosition position) {
1037 if (position == MenuDelegate::DROP_NONE) 1037 if (position == MenuDelegate::DROP_NONE)
1038 return; 1038 return;
1039 1039
1040 gfx::Rect bounds = CalculateDropIndicatorBounds(item, position); 1040 gfx::Rect bounds = CalculateDropIndicatorBounds(item, position);
1041 canvas->FillRectInt(kDropIndicatorColor, bounds.x(), bounds.y(), 1041 canvas->FillRectInt(kDropIndicatorColor, bounds.x(), bounds.y(),
1042 bounds.width(), bounds.height()); 1042 bounds.width(), bounds.height());
1043 } 1043 }
1044 1044
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 MenuItemView* item = GetDescendantByID(item_id); 1203 MenuItemView* item = GetDescendantByID(item_id);
1204 DCHECK(item); 1204 DCHECK(item);
1205 item->SetIcon(icon); 1205 item->SetIcon(icon);
1206 } 1206 }
1207 1207
1208 void MenuItemView::SetIcon(const SkBitmap& icon) { 1208 void MenuItemView::SetIcon(const SkBitmap& icon) {
1209 icon_ = icon; 1209 icon_ = icon;
1210 SchedulePaint(); 1210 SchedulePaint();
1211 } 1211 }
1212 1212
1213 void MenuItemView::Paint(ChromeCanvas* canvas) { 1213 void MenuItemView::Paint(gfx::Canvas* canvas) {
1214 Paint(canvas, false); 1214 Paint(canvas, false);
1215 } 1215 }
1216 1216
1217 gfx::Size MenuItemView::GetPreferredSize() { 1217 gfx::Size MenuItemView::GetPreferredSize() {
1218 gfx::Font& font = GetRootMenuItem()->font_; 1218 gfx::Font& font = GetRootMenuItem()->font_;
1219 return gfx::Size( 1219 return gfx::Size(
1220 font.GetStringWidth(title_) + label_start + item_right_margin, 1220 font.GetStringWidth(title_) + label_start + item_right_margin,
1221 font.height() + GetBottomMargin() + GetTopMargin()); 1221 font.height() + GetBottomMargin() + GetTopMargin());
1222 } 1222 }
1223 1223
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 1367
1368 BOOL show_cues; 1368 BOOL show_cues;
1369 show_mnemonics = 1369 show_mnemonics =
1370 (SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &show_cues, 0) && 1370 (SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &show_cues, 0) &&
1371 show_cues == TRUE); 1371 show_cues == TRUE);
1372 } 1372 }
1373 1373
1374 int MenuItemView::GetDrawStringFlags() { 1374 int MenuItemView::GetDrawStringFlags() {
1375 int flags = 0; 1375 int flags = 0;
1376 if (UILayoutIsRightToLeft()) 1376 if (UILayoutIsRightToLeft())
1377 flags |= ChromeCanvas::TEXT_ALIGN_RIGHT; 1377 flags |= gfx::Canvas::TEXT_ALIGN_RIGHT;
1378 else 1378 else
1379 flags |= ChromeCanvas::TEXT_ALIGN_LEFT; 1379 flags |= gfx::Canvas::TEXT_ALIGN_LEFT;
1380 1380
1381 if (has_mnemonics_) { 1381 if (has_mnemonics_) {
1382 if (show_mnemonics) 1382 if (show_mnemonics)
1383 flags |= ChromeCanvas::SHOW_PREFIX; 1383 flags |= gfx::Canvas::SHOW_PREFIX;
1384 else 1384 else
1385 flags |= ChromeCanvas::HIDE_PREFIX; 1385 flags |= gfx::Canvas::HIDE_PREFIX;
1386 } 1386 }
1387 return flags; 1387 return flags;
1388 } 1388 }
1389 1389
1390 void MenuItemView::AddEmptyMenus() { 1390 void MenuItemView::AddEmptyMenus() {
1391 DCHECK(HasSubmenu()); 1391 DCHECK(HasSubmenu());
1392 if (submenu_->GetChildViewCount() == 0) { 1392 if (submenu_->GetChildViewCount() == 0) {
1393 submenu_->AddChildView(0, new EmptyMenuMenuItem(this)); 1393 submenu_->AddChildView(0, new EmptyMenuMenuItem(this));
1394 } else { 1394 } else {
1395 for (int i = 0, item_count = submenu_->GetMenuItemCount(); i < item_count; 1395 for (int i = 0, item_count = submenu_->GetMenuItemCount(); i < item_count;
(...skipping 20 matching lines...) Expand all
1416 } 1416 }
1417 } 1417 }
1418 } 1418 }
1419 1419
1420 void MenuItemView::AdjustBoundsForRTLUI(RECT* rect) const { 1420 void MenuItemView::AdjustBoundsForRTLUI(RECT* rect) const {
1421 gfx::Rect mirrored_rect(*rect); 1421 gfx::Rect mirrored_rect(*rect);
1422 mirrored_rect.set_x(MirroredLeftPointForRect(mirrored_rect)); 1422 mirrored_rect.set_x(MirroredLeftPointForRect(mirrored_rect));
1423 *rect = mirrored_rect.ToRECT(); 1423 *rect = mirrored_rect.ToRECT();
1424 } 1424 }
1425 1425
1426 void MenuItemView::Paint(ChromeCanvas* canvas, bool for_drag) { 1426 void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) {
1427 bool render_selection = 1427 bool render_selection =
1428 (!for_drag && IsSelected() && 1428 (!for_drag && IsSelected() &&
1429 parent_menu_item_->GetSubmenu()->GetShowSelection(this)); 1429 parent_menu_item_->GetSubmenu()->GetShowSelection(this));
1430 int state = render_selection ? MPI_HOT : 1430 int state = render_selection ? MPI_HOT :
1431 (IsEnabled() ? MPI_NORMAL : MPI_DISABLED); 1431 (IsEnabled() ? MPI_NORMAL : MPI_DISABLED);
1432 HDC dc = canvas->beginPlatformPaint(); 1432 HDC dc = canvas->beginPlatformPaint();
1433 1433
1434 // The gutter is rendered before the background. 1434 // The gutter is rendered before the background.
1435 if (render_gutter && !for_drag) { 1435 if (render_gutter && !for_drag) {
1436 RECT gutter_bounds = { label_start - kGutterToLabel - gutter_width, 0, 0, 1436 RECT gutter_bounds = { label_start - kGutterToLabel - gutter_width, 0, 0,
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1817 DCHECK(item); 1817 DCHECK(item);
1818 // Points are in the coordinates of the submenu, need to map to that of 1818 // Points are in the coordinates of the submenu, need to map to that of
1819 // the selected item. Additionally source may not be the parent of 1819 // the selected item. Additionally source may not be the parent of
1820 // the selected item, so need to map to screen first then to item. 1820 // the selected item, so need to map to screen first then to item.
1821 gfx::Point press_loc(press_x_, press_y_); 1821 gfx::Point press_loc(press_x_, press_y_);
1822 View::ConvertPointToScreen(source->GetScrollViewContainer(), &press_loc); 1822 View::ConvertPointToScreen(source->GetScrollViewContainer(), &press_loc);
1823 View::ConvertPointToView(NULL, item, &press_loc); 1823 View::ConvertPointToView(NULL, item, &press_loc);
1824 gfx::Point drag_loc(event.location()); 1824 gfx::Point drag_loc(event.location());
1825 View::ConvertPointToScreen(source->GetScrollViewContainer(), &drag_loc); 1825 View::ConvertPointToScreen(source->GetScrollViewContainer(), &drag_loc);
1826 View::ConvertPointToView(NULL, item, &drag_loc); 1826 View::ConvertPointToView(NULL, item, &drag_loc);
1827 ChromeCanvas canvas(item->width(), item->height(), false); 1827 gfx::Canvas canvas(item->width(), item->height(), false);
1828 item->Paint(&canvas, true); 1828 item->Paint(&canvas, true);
1829 1829
1830 scoped_refptr<OSExchangeData> data(new OSExchangeData); 1830 scoped_refptr<OSExchangeData> data(new OSExchangeData);
1831 item->GetDelegate()->WriteDragData(item, data.get()); 1831 item->GetDelegate()->WriteDragData(item, data.get());
1832 drag_utils::SetDragImageOnDataObject(canvas, item->width(), 1832 drag_utils::SetDragImageOnDataObject(canvas, item->width(),
1833 item->height(), press_loc.x(), 1833 item->height(), press_loc.x(),
1834 press_loc.y(), data); 1834 press_loc.y(), data);
1835 1835
1836 scoped_refptr<BaseDragSource> drag_source(new BaseDragSource); 1836 scoped_refptr<BaseDragSource> drag_source(new BaseDragSource);
1837 int drag_ops = item->GetDelegate()->GetDragOperations(item); 1837 int drag_ops = item->GetDelegate()->GetDragOperations(item);
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
2811 if (!scroll_task_.get()) 2811 if (!scroll_task_.get())
2812 scroll_task_.reset(new MenuScrollTask()); 2812 scroll_task_.reset(new MenuScrollTask());
2813 scroll_task_->Update(part); 2813 scroll_task_->Update(part);
2814 } 2814 }
2815 2815
2816 void MenuController::StopScrolling() { 2816 void MenuController::StopScrolling() {
2817 scroll_task_.reset(NULL); 2817 scroll_task_.reset(NULL);
2818 } 2818 }
2819 2819
2820 } // namespace views 2820 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/menu/chrome_menu.h ('k') | views/controls/menu/menu_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698