OLD | NEW |
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 "chrome/browser/views/bookmark_bar_view.h" | 5 #include "chrome/browser/views/bookmark_bar_view.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "app/gfx/canvas.h" | 9 #include "app/gfx/canvas.h" |
10 #include "app/gfx/text_elider.h" | 10 #include "app/gfx/text_elider.h" |
11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
12 #include "app/os_exchange_data.h" | 12 #include "app/os_exchange_data.h" |
13 #include "app/resource_bundle.h" | 13 #include "app/resource_bundle.h" |
14 #include "app/win_util.h" | |
15 #include "base/string_util.h" | 14 #include "base/string_util.h" |
16 #include "base/base_drag_source.h" | |
17 #include "chrome/browser/bookmarks/bookmark_context_menu.h" | 15 #include "chrome/browser/bookmarks/bookmark_context_menu.h" |
18 #include "chrome/browser/bookmarks/bookmark_utils.h" | 16 #include "chrome/browser/bookmarks/bookmark_utils.h" |
19 #include "chrome/browser/browser.h" | 17 #include "chrome/browser/browser.h" |
20 #include "chrome/browser/browser_theme_provider.h" | 18 #include "chrome/browser/browser_theme_provider.h" |
21 #include "chrome/browser/extensions/extension_view.h" | 19 #include "chrome/browser/extensions/extension_view.h" |
22 #include "chrome/browser/extensions/extensions_service.h" | 20 #include "chrome/browser/extensions/extensions_service.h" |
23 #include "chrome/browser/metrics/user_metrics.h" | 21 #include "chrome/browser/metrics/user_metrics.h" |
24 #include "chrome/browser/profile.h" | 22 #include "chrome/browser/profile.h" |
25 #include "chrome/browser/renderer_host/render_view_host.h" | 23 #include "chrome/browser/renderer_host/render_view_host.h" |
26 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 24 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
(...skipping 11 matching lines...) Expand all Loading... |
38 #include "grit/theme_resources.h" | 36 #include "grit/theme_resources.h" |
39 #include "skia/ext/skia_utils.h" | 37 #include "skia/ext/skia_utils.h" |
40 #include "views/controls/button/menu_button.h" | 38 #include "views/controls/button/menu_button.h" |
41 #include "views/controls/menu/chrome_menu.h" | 39 #include "views/controls/menu/chrome_menu.h" |
42 #include "views/drag_utils.h" | 40 #include "views/drag_utils.h" |
43 #include "views/view_constants.h" | 41 #include "views/view_constants.h" |
44 #include "views/widget/tooltip_manager.h" | 42 #include "views/widget/tooltip_manager.h" |
45 #include "views/widget/widget.h" | 43 #include "views/widget/widget.h" |
46 #include "views/window/window.h" | 44 #include "views/window/window.h" |
47 | 45 |
| 46 #if defined(OS_WIN) |
| 47 #include "app/win_util.h" |
| 48 #include "base/base_drag_source.h" |
| 49 #endif |
| 50 |
48 using views::CustomButton; | 51 using views::CustomButton; |
49 using views::DropTargetEvent; | 52 using views::DropTargetEvent; |
50 using views::MenuButton; | 53 using views::MenuButton; |
51 using views::MenuItemView; | 54 using views::MenuItemView; |
52 using views::View; | 55 using views::View; |
53 | 56 |
54 // How much we want the bookmark bar to overlap the toolbar when in its | 57 // How much we want the bookmark bar to overlap the toolbar when in its |
55 // 'always shown' mode. | 58 // 'always shown' mode. |
56 static const double kToolbarOverlap = 4.0; | 59 static const double kToolbarOverlap = 4.0; |
57 | 60 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 | 142 |
140 // Returns the tooltip text for the specified url and title. The returned | 143 // Returns the tooltip text for the specified url and title. The returned |
141 // text is clipped to fit within the bounds of the monitor. | 144 // text is clipped to fit within the bounds of the monitor. |
142 // | 145 // |
143 // Note that we adjust the direction of both the URL and the title based on the | 146 // Note that we adjust the direction of both the URL and the title based on the |
144 // locale so that pure LTR strings are displayed properly in RTL locales. | 147 // locale so that pure LTR strings are displayed properly in RTL locales. |
145 static std::wstring CreateToolTipForURLAndTitle(const gfx::Point& screen_loc, | 148 static std::wstring CreateToolTipForURLAndTitle(const gfx::Point& screen_loc, |
146 const GURL& url, | 149 const GURL& url, |
147 const std::wstring& title, | 150 const std::wstring& title, |
148 const std::wstring& languages) { | 151 const std::wstring& languages) { |
149 const gfx::Rect monitor_bounds = win_util::GetMonitorBoundsForRect( | 152 #if defined(OS_WIN) |
| 153 gfx::Rect monitor_bounds = win_util::GetMonitorBoundsForRect( |
150 gfx::Rect(screen_loc.x(), screen_loc.y(), 1, 1)); | 154 gfx::Rect(screen_loc.x(), screen_loc.y(), 1, 1)); |
| 155 #else |
| 156 gfx::Rect monitor_bounds(0, 0, 10000, 10000); |
| 157 NOTIMPLEMENTED(); |
| 158 #endif |
151 gfx::Font tt_font = views::TooltipManager::GetDefaultFont(); | 159 gfx::Font tt_font = views::TooltipManager::GetDefaultFont(); |
152 std::wstring result; | 160 std::wstring result; |
153 | 161 |
154 // First the title. | 162 // First the title. |
155 if (!title.empty()) { | 163 if (!title.empty()) { |
156 std::wstring localized_title; | 164 std::wstring localized_title; |
157 if (l10n_util::AdjustStringForLocaleDirection(title, &localized_title)) | 165 if (l10n_util::AdjustStringForLocaleDirection(title, &localized_title)) |
158 result.append(gfx::ElideText(localized_title, | 166 result.append(gfx::ElideText(localized_title, |
159 tt_font, | 167 tt_font, |
160 monitor_bounds.width())); | 168 monitor_bounds.width())); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); | 273 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); |
266 }; | 274 }; |
267 | 275 |
268 } // namespace | 276 } // namespace |
269 | 277 |
270 // DropInfo ------------------------------------------------------------------- | 278 // DropInfo ------------------------------------------------------------------- |
271 | 279 |
272 // Tracks drops on the BookmarkBarView. | 280 // Tracks drops on the BookmarkBarView. |
273 | 281 |
274 struct BookmarkBarView::DropInfo { | 282 struct BookmarkBarView::DropInfo { |
275 DropInfo() : drop_index(-1), is_menu_showing(false), valid(false) {} | 283 DropInfo() : valid(false), drop_index(-1), is_menu_showing(false) {} |
276 | 284 |
277 // Whether the data is valid. | 285 // Whether the data is valid. |
278 bool valid; | 286 bool valid; |
279 | 287 |
280 // Index into the model the drop is over. This is relative to the root node. | 288 // Index into the model the drop is over. This is relative to the root node. |
281 int drop_index; | 289 int drop_index; |
282 | 290 |
283 // If true, the menu is being shown. | 291 // If true, the menu is being shown. |
284 bool is_menu_showing; | 292 bool is_menu_showing; |
285 | 293 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 static const SkBitmap& GetGroupIcon() { | 363 static const SkBitmap& GetGroupIcon() { |
356 if (!kFolderIcon) { | 364 if (!kFolderIcon) { |
357 kFolderIcon = ResourceBundle::GetSharedInstance(). | 365 kFolderIcon = ResourceBundle::GetSharedInstance(). |
358 GetBitmapNamed(IDR_BOOKMARK_BAR_FOLDER); | 366 GetBitmapNamed(IDR_BOOKMARK_BAR_FOLDER); |
359 } | 367 } |
360 return *kFolderIcon; | 368 return *kFolderIcon; |
361 } | 369 } |
362 | 370 |
363 BookmarkBarView::BookmarkBarView(Profile* profile, Browser* browser) | 371 BookmarkBarView::BookmarkBarView(Profile* profile, Browser* browser) |
364 : profile_(NULL), | 372 : profile_(NULL), |
365 browser_(browser), | |
366 page_navigator_(NULL), | 373 page_navigator_(NULL), |
367 model_(NULL), | 374 model_(NULL), |
368 bookmark_menu_(NULL), | 375 bookmark_menu_(NULL), |
369 bookmark_drop_menu_(NULL), | 376 bookmark_drop_menu_(NULL), |
370 other_bookmarked_button_(NULL), | 377 other_bookmarked_button_(NULL), |
371 model_changed_listener_(NULL), | 378 model_changed_listener_(NULL), |
372 show_folder_drop_menu_task_(NULL), | 379 show_folder_drop_menu_task_(NULL), |
373 overflow_button_(NULL), | 380 overflow_button_(NULL), |
374 instructions_(NULL), | 381 instructions_(NULL), |
375 bookmarks_separator_view_(NULL), | 382 bookmarks_separator_view_(NULL), |
| 383 browser_(browser), |
376 throbbing_view_(NULL) { | 384 throbbing_view_(NULL) { |
377 SetID(VIEW_ID_BOOKMARK_BAR); | 385 SetID(VIEW_ID_BOOKMARK_BAR); |
378 Init(); | 386 Init(); |
379 SetProfile(profile); | 387 SetProfile(profile); |
380 | 388 |
381 if (IsAlwaysShown()) { | 389 if (IsAlwaysShown()) { |
382 size_animation_->Reset(1); | 390 size_animation_->Reset(1); |
383 } else { | 391 } else { |
384 size_animation_->Reset(0); | 392 size_animation_->Reset(0); |
385 } | 393 } |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 case NotificationType::BOOKMARK_BUBBLE_SHOWN: | 1269 case NotificationType::BOOKMARK_BUBBLE_SHOWN: |
1262 StopThrobbing(true); | 1270 StopThrobbing(true); |
1263 bubble_url_ = *(Details<GURL>(details).ptr()); | 1271 bubble_url_ = *(Details<GURL>(details).ptr()); |
1264 StartThrobbing(); | 1272 StartThrobbing(); |
1265 break; | 1273 break; |
1266 | 1274 |
1267 case NotificationType::BOOKMARK_BUBBLE_HIDDEN: | 1275 case NotificationType::BOOKMARK_BUBBLE_HIDDEN: |
1268 StopThrobbing(false); | 1276 StopThrobbing(false); |
1269 bubble_url_ = GURL(); | 1277 bubble_url_ = GURL(); |
1270 break; | 1278 break; |
| 1279 |
| 1280 default: |
| 1281 NOTREACHED(); |
| 1282 break; |
1271 } | 1283 } |
1272 } | 1284 } |
1273 | 1285 |
1274 void BookmarkBarView::NotifyModelChanged() { | 1286 void BookmarkBarView::NotifyModelChanged() { |
1275 if (model_changed_listener_) | 1287 if (model_changed_listener_) |
1276 model_changed_listener_->ModelChanged(); | 1288 model_changed_listener_->ModelChanged(); |
1277 } | 1289 } |
1278 | 1290 |
1279 void BookmarkBarView::ShowDropFolderForNode(BookmarkNode* node) { | 1291 void BookmarkBarView::ShowDropFolderForNode(BookmarkNode* node) { |
1280 if (bookmark_drop_menu_) { | 1292 if (bookmark_drop_menu_) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 | 1353 |
1342 void BookmarkBarView::StartShowFolderDropMenuTimer(BookmarkNode* node) { | 1354 void BookmarkBarView::StartShowFolderDropMenuTimer(BookmarkNode* node) { |
1343 if (testing_) { | 1355 if (testing_) { |
1344 // So that tests can run as fast as possible disable the delay during | 1356 // So that tests can run as fast as possible disable the delay during |
1345 // testing. | 1357 // testing. |
1346 ShowDropFolderForNode(node); | 1358 ShowDropFolderForNode(node); |
1347 return; | 1359 return; |
1348 } | 1360 } |
1349 DCHECK(!show_folder_drop_menu_task_); | 1361 DCHECK(!show_folder_drop_menu_task_); |
1350 show_folder_drop_menu_task_ = new ShowFolderDropMenuTask(this, node); | 1362 show_folder_drop_menu_task_ = new ShowFolderDropMenuTask(this, node); |
| 1363 #if defined(OS_WIN) |
1351 static DWORD delay = 0; | 1364 static DWORD delay = 0; |
1352 if (!delay && !SystemParametersInfo(SPI_GETMENUSHOWDELAY, 0, &delay, 0)) { | 1365 if (!delay && !SystemParametersInfo(SPI_GETMENUSHOWDELAY, 0, &delay, 0)) |
1353 delay = kShowFolderDropMenuDelay; | 1366 delay = kShowFolderDropMenuDelay; |
1354 } | 1367 #else |
| 1368 int delay = kShowFolderDropMenuDelay; |
| 1369 #endif |
1355 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 1370 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
1356 show_folder_drop_menu_task_, delay); | 1371 show_folder_drop_menu_task_, delay); |
1357 } | 1372 } |
1358 | 1373 |
1359 int BookmarkBarView::CalculateDropOperation(const DropTargetEvent& event, | 1374 int BookmarkBarView::CalculateDropOperation(const DropTargetEvent& event, |
1360 const BookmarkDragData& data, | 1375 const BookmarkDragData& data, |
1361 int* index, | 1376 int* index, |
1362 bool* drop_on, | 1377 bool* drop_on, |
1363 bool* is_over_overflow, | 1378 bool* is_over_overflow, |
1364 bool* is_over_other) { | 1379 bool* is_over_other) { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1519 } | 1534 } |
1520 | 1535 |
1521 void BookmarkBarView::StopThrobbing(bool immediate) { | 1536 void BookmarkBarView::StopThrobbing(bool immediate) { |
1522 if (!throbbing_view_) | 1537 if (!throbbing_view_) |
1523 return; | 1538 return; |
1524 | 1539 |
1525 // If not immediate, cycle through 2 more complete cycles. | 1540 // If not immediate, cycle through 2 more complete cycles. |
1526 throbbing_view_->StartThrobbing(immediate ? 0 : 4); | 1541 throbbing_view_->StartThrobbing(immediate ? 0 : 4); |
1527 throbbing_view_ = NULL; | 1542 throbbing_view_ = NULL; |
1528 } | 1543 } |
OLD | NEW |