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

Side by Side Diff: chrome/browser/views/bookmark_menu_button.cc

Issue 42460: Adds a bookmark menu. This is experimental. To turn on you need... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 9 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/views/bookmark_menu_button.h"
6
7 #include "chrome/browser/bookmarks/bookmark_model.h"
8 #include "chrome/browser/bookmarks/bookmark_utils.h"
9 #include "chrome/browser/browser.h"
10 #include "chrome/browser/profile.h"
11 #include "chrome/browser/view_ids.h"
12 #include "chrome/common/os_exchange_data.h"
13 #include "chrome/common/resource_bundle.h"
14 #include "chrome/views/widget/widget.h"
15 #include "grit/theme_resources.h"
16
17 BookmarkMenuButton::BookmarkMenuButton(Browser* browser)
18 : views::MenuButton(NULL, std::wstring(), NULL, false),
19 browser_(browser),
20 bookmark_drop_menu_(NULL),
21 drop_operation_(0) {
22 set_menu_delegate(this);
23 SetID(VIEW_ID_BOOKMARK_MENU);
24
25 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
26 // TODO (sky): if we keep this code, we need real icons, a11y support, and a
27 // tooltip.
28 SetIcon(*rb.GetBitmapNamed(IDR_MENU_BOOKMARK));
29 }
30
31 BookmarkMenuButton::~BookmarkMenuButton() {
32 if (bookmark_drop_menu_)
33 bookmark_drop_menu_->set_observer(NULL);
34 }
35
36 bool BookmarkMenuButton::CanDrop(const OSExchangeData& data) {
37 BookmarkModel* bookmark_model = GetBookmarkModel();
38 if (!bookmark_model || !bookmark_model->IsLoaded())
39 return false;
40
41 drag_data_ = BookmarkDragData();
42 // Only accept drops of 1 node, which is the case for all data dragged from
43 // bookmark bar and menus.
44 return drag_data_.Read(data) && drag_data_.has_single_url();
45 }
46
47 int BookmarkMenuButton::OnDragUpdated(const views::DropTargetEvent& event) {
48 if (!drag_data_.is_valid())
49 return 0;
50
51 BookmarkModel* bookmark_model = GetBookmarkModel();
52 drop_operation_ = bookmark_utils::BookmarkDropOperation(
53 browser_->profile(), event, drag_data_,
54 bookmark_model->GetBookmarkBarNode(),
55 bookmark_model->GetBookmarkBarNode()->GetChildCount());
56 if (drop_operation_ != 0)
57 StartShowFolderDropMenuTimer();
58 else
59 StopShowFolderDropMenuTimer();
60 return drop_operation_;
61 }
62
63 void BookmarkMenuButton::OnDragExited() {
64 StopShowFolderDropMenuTimer();
65 drag_data_ = BookmarkDragData();
66 }
67
68 int BookmarkMenuButton::OnPerformDrop(const views::DropTargetEvent& event) {
69 StopShowFolderDropMenuTimer();
70
71 if (bookmark_drop_menu_)
72 bookmark_drop_menu_->Cancel();
73
74 // Reset the drag data to take as little memory as needed.
75 BookmarkDragData data = drag_data_;
76 drag_data_ = BookmarkDragData();
77
78 if (!drop_operation_)
79 return DragDropTypes::DRAG_NONE;
80
81 BookmarkModel* model = GetBookmarkModel();
82 if (!model)
83 return DragDropTypes::DRAG_NONE;
84
85 BookmarkNode* parent = model->GetBookmarkBarNode();
86 return bookmark_utils::PerformBookmarkDrop(
87 browser_->profile(), data, parent, parent->GetChildCount());
88 }
89
90 void BookmarkMenuButton::BookmarkMenuDeleted(
91 BookmarkMenuController* controller) {
92 bookmark_drop_menu_ = NULL;
93 }
94
95 void BookmarkMenuButton::RunMenu(views::View* source,
96 const CPoint& pt,
97 gfx::NativeView hwnd) {
98 RunMenu(source, pt, hwnd, false);
99 }
100
101 void BookmarkMenuButton::RunMenu(views::View* source,
102 const CPoint& pt,
103 gfx::NativeView hwnd,
104 bool for_drop) {
105 Profile* profile = browser_->profile();
106 BookmarkMenuController* menu = new BookmarkMenuController(
107 browser_, profile, browser_->GetSelectedTabContents(), hwnd,
108 GetBookmarkModel()->GetBookmarkBarNode(), 0, true);
109
110 views::MenuItemView::AnchorPosition anchor = views::MenuItemView::TOPRIGHT;
111 if (UILayoutIsRightToLeft())
112 anchor = views::MenuItemView::TOPLEFT;
113 gfx::Point button_origin;
114 ConvertPointToScreen(this, &button_origin);
115 gfx::Rect menu_bounds(button_origin.x(), button_origin.y(), width(),
116 height());
117 if (for_drop) {
118 bookmark_drop_menu_ = menu;
119 bookmark_drop_menu_->set_observer(this);
120 }
121 menu->RunMenuAt(menu_bounds, views::MenuItemView::TOPRIGHT, for_drop);
122 }
123
124 BookmarkModel* BookmarkMenuButton::GetBookmarkModel() {
125 return browser_->profile()->GetBookmarkModel();
126 }
127
128 void BookmarkMenuButton::StartShowFolderDropMenuTimer() {
129 if (show_drop_menu_timer_.IsRunning())
130 return;
131
132 static DWORD delay = 0;
133 if (!delay && !SystemParametersInfo(SPI_GETMENUSHOWDELAY, 0, &delay, 0))
134 delay = 400;
135 show_drop_menu_timer_.Start(base::TimeDelta::FromMilliseconds(delay),
136 this, &BookmarkMenuButton::ShowDropMenu);
137 }
138
139 void BookmarkMenuButton::StopShowFolderDropMenuTimer() {
140 show_drop_menu_timer_.Stop();
141 }
142
143 void BookmarkMenuButton::ShowDropMenu() {
144 RunMenu(NULL, CPoint(), GetWidget()->GetNativeView(), true);
145 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698