OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/views/tabs/tab_strip.h" | 5 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windowsx.h> | 8 #include <windowsx.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 void TabStrip::StopAnimating(bool layout) { | 985 void TabStrip::StopAnimating(bool layout) { |
986 if (!IsAnimating()) | 986 if (!IsAnimating()) |
987 return; | 987 return; |
988 | 988 |
989 bounds_animator_.Cancel(); | 989 bounds_animator_.Cancel(); |
990 | 990 |
991 if (layout) | 991 if (layout) |
992 DoLayout(); | 992 DoLayout(); |
993 } | 993 } |
994 | 994 |
| 995 void TabStrip::FileSupported(const GURL& url, bool supported) { |
| 996 if (drop_info_.get() && drop_info_->url == url) |
| 997 drop_info_->file_supported = supported; |
| 998 } |
| 999 |
995 const ui::ListSelectionModel& TabStrip::GetSelectionModel() { | 1000 const ui::ListSelectionModel& TabStrip::GetSelectionModel() { |
996 return controller_->GetSelectionModel(); | 1001 return controller_->GetSelectionModel(); |
997 } | 1002 } |
998 | 1003 |
999 bool TabStrip::SupportsMultipleSelection() { | 1004 bool TabStrip::SupportsMultipleSelection() { |
1000 // TODO: currently only allow single selection in touch layout mode. | 1005 // TODO: currently only allow single selection in touch layout mode. |
1001 return touch_layout_.get() == NULL; | 1006 return touch_layout_.get() == NULL; |
1002 } | 1007 } |
1003 | 1008 |
1004 void TabStrip::SelectTab(Tab* tab) { | 1009 void TabStrip::SelectTab(Tab* tab) { |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1395 if (immersive_style_) | 1400 if (immersive_style_) |
1396 return gfx::Size(needed_width, Tab::GetImmersiveHeight()); | 1401 return gfx::Size(needed_width, Tab::GetImmersiveHeight()); |
1397 return gfx::Size(needed_width, Tab::GetMinimumUnselectedSize().height()); | 1402 return gfx::Size(needed_width, Tab::GetMinimumUnselectedSize().height()); |
1398 } | 1403 } |
1399 | 1404 |
1400 void TabStrip::OnDragEntered(const DropTargetEvent& event) { | 1405 void TabStrip::OnDragEntered(const DropTargetEvent& event) { |
1401 // Force animations to stop, otherwise it makes the index calculation tricky. | 1406 // Force animations to stop, otherwise it makes the index calculation tricky. |
1402 StopAnimating(true); | 1407 StopAnimating(true); |
1403 | 1408 |
1404 UpdateDropIndex(event); | 1409 UpdateDropIndex(event); |
| 1410 |
| 1411 GURL url; |
| 1412 string16 title; |
| 1413 |
| 1414 // Check whether the event data includes supported drop data. |
| 1415 if (event.data().GetURLAndTitle(&url, &title) && url.is_valid()) { |
| 1416 drop_info_->url = url; |
| 1417 |
| 1418 // For file:// URLs, kick off a MIME type request in case they're dropped. |
| 1419 if (url.SchemeIsFile()) |
| 1420 controller()->CheckFileSupported(url); |
| 1421 } |
1405 } | 1422 } |
1406 | 1423 |
1407 int TabStrip::OnDragUpdated(const DropTargetEvent& event) { | 1424 int TabStrip::OnDragUpdated(const DropTargetEvent& event) { |
| 1425 // Update the drop index even if the file is unsupported, to allow |
| 1426 // dragging a file to the contents of another tab. |
1408 UpdateDropIndex(event); | 1427 UpdateDropIndex(event); |
| 1428 |
| 1429 if (!drop_info_->file_supported) |
| 1430 return ui::DragDropTypes::DRAG_NONE; |
| 1431 |
1409 return GetDropEffect(event); | 1432 return GetDropEffect(event); |
1410 } | 1433 } |
1411 | 1434 |
1412 void TabStrip::OnDragExited() { | 1435 void TabStrip::OnDragExited() { |
1413 SetDropIndex(-1, false); | 1436 SetDropIndex(-1, false); |
1414 } | 1437 } |
1415 | 1438 |
1416 int TabStrip::OnPerformDrop(const DropTargetEvent& event) { | 1439 int TabStrip::OnPerformDrop(const DropTargetEvent& event) { |
1417 if (!drop_info_.get()) | 1440 if (!drop_info_.get()) |
1418 return ui::DragDropTypes::DRAG_NONE; | 1441 return ui::DragDropTypes::DRAG_NONE; |
1419 | 1442 |
1420 const int drop_index = drop_info_->drop_index; | 1443 const int drop_index = drop_info_->drop_index; |
1421 const bool drop_before = drop_info_->drop_before; | 1444 const bool drop_before = drop_info_->drop_before; |
| 1445 const bool file_supported = drop_info_->file_supported; |
1422 | 1446 |
1423 // Hide the drop indicator. | 1447 // Hide the drop indicator. |
1424 SetDropIndex(-1, false); | 1448 SetDropIndex(-1, false); |
1425 | 1449 |
| 1450 // Do nothing if the file was unsupported or the URL is invalid. The URL may |
| 1451 // have been changed after |drop_info_| was created. |
1426 GURL url; | 1452 GURL url; |
1427 string16 title; | 1453 string16 title; |
1428 if (!event.data().GetURLAndTitle(&url, &title) || !url.is_valid()) | 1454 if (!file_supported || |
| 1455 !event.data().GetURLAndTitle(&url, &title) || !url.is_valid()) |
1429 return ui::DragDropTypes::DRAG_NONE; | 1456 return ui::DragDropTypes::DRAG_NONE; |
1430 | 1457 |
1431 controller()->PerformDrop(drop_before, drop_index, url); | 1458 controller()->PerformDrop(drop_before, drop_index, url); |
1432 | 1459 |
1433 return GetDropEffect(event); | 1460 return GetDropEffect(event); |
1434 } | 1461 } |
1435 | 1462 |
1436 void TabStrip::GetAccessibleState(ui::AccessibleViewState* state) { | 1463 void TabStrip::GetAccessibleState(ui::AccessibleViewState* state) { |
1437 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; | 1464 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; |
1438 } | 1465 } |
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2427 } | 2454 } |
2428 | 2455 |
2429 // TabStrip::DropInfo ---------------------------------------------------------- | 2456 // TabStrip::DropInfo ---------------------------------------------------------- |
2430 | 2457 |
2431 TabStrip::DropInfo::DropInfo(int drop_index, | 2458 TabStrip::DropInfo::DropInfo(int drop_index, |
2432 bool drop_before, | 2459 bool drop_before, |
2433 bool point_down, | 2460 bool point_down, |
2434 views::Widget* context) | 2461 views::Widget* context) |
2435 : drop_index(drop_index), | 2462 : drop_index(drop_index), |
2436 drop_before(drop_before), | 2463 drop_before(drop_before), |
2437 point_down(point_down) { | 2464 point_down(point_down), |
| 2465 file_supported(true) { |
2438 arrow_view = new views::ImageView; | 2466 arrow_view = new views::ImageView; |
2439 arrow_view->SetImage(GetDropArrowImage(point_down)); | 2467 arrow_view->SetImage(GetDropArrowImage(point_down)); |
2440 | 2468 |
2441 arrow_window = new views::Widget; | 2469 arrow_window = new views::Widget; |
2442 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 2470 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
2443 params.keep_on_top = true; | 2471 params.keep_on_top = true; |
2444 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 2472 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
2445 params.accept_events = false; | 2473 params.accept_events = false; |
2446 params.can_activate = false; | 2474 params.can_activate = false; |
2447 params.bounds = gfx::Rect(drop_indicator_width, drop_indicator_height); | 2475 params.bounds = gfx::Rect(drop_indicator_width, drop_indicator_height); |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2745 #if defined(USE_AURA) | 2773 #if defined(USE_AURA) |
2746 return chrome::GetHostDesktopTypeForNativeView( | 2774 return chrome::GetHostDesktopTypeForNativeView( |
2747 GetWidget()->GetNativeView()) == chrome::HOST_DESKTOP_TYPE_ASH; | 2775 GetWidget()->GetNativeView()) == chrome::HOST_DESKTOP_TYPE_ASH; |
2748 #else | 2776 #else |
2749 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) | 2777 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) |
2750 return false; | 2778 return false; |
2751 #endif | 2779 #endif |
2752 | 2780 |
2753 return true; | 2781 return true; |
2754 } | 2782 } |
OLD | NEW |