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