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_->url == url) | |
sky
2013/11/26 00:12:29
How do you know drop_info_ is non-null?
michaelpg
2013/11/26 04:50:13
It definitely could be null, thanks.
| |
995 drop_info_->file_supported = supported; | |
sky
2013/11/26 00:12:29
If supported is false should we destroy drop_info_
michaelpg
2013/11/26 04:50:13
No, it would just get re-created in SetDropIndex.
| |
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 } else { | |
1420 drop_info_->file_supported = false; | |
sky
2013/11/26 00:12:29
Can't we set drop_info_ to NULL here?
michaelpg
2013/11/26 04:50:13
No, we need drop_info in case text is being dragge
| |
1421 } | |
1403 } | 1422 } |
1404 | 1423 |
1405 int TabStrip::OnDragUpdated(const DropTargetEvent& event) { | 1424 int TabStrip::OnDragUpdated(const DropTargetEvent& event) { |
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 |
1441 if (!drop_info_->file_supported) { | |
1442 SetDropIndex(-1, false); | |
1443 return ui::DragDropTypes::DRAG_NONE; | |
1444 } | |
1445 | |
1418 const int drop_index = drop_info_->drop_index; | 1446 const int drop_index = drop_info_->drop_index; |
1419 const bool drop_before = drop_info_->drop_before; | 1447 const bool drop_before = drop_info_->drop_before; |
1448 const GURL drop_url = drop_info_->url; | |
1420 | 1449 |
1421 // Hide the drop indicator. | 1450 // Hide the drop indicator. |
1422 SetDropIndex(-1, false); | 1451 SetDropIndex(-1, false); |
1423 | 1452 |
1424 GURL url; | 1453 controller()->PerformDrop(drop_before, drop_index, drop_url); |
1425 string16 title; | |
1426 if (!event.data().GetURLAndTitle(&url, &title) || !url.is_valid()) | |
1427 return ui::DragDropTypes::DRAG_NONE; | |
1428 | |
1429 controller()->PerformDrop(drop_before, drop_index, url); | |
1430 | 1454 |
1431 return GetDropEffect(event); | 1455 return GetDropEffect(event); |
1432 } | 1456 } |
1433 | 1457 |
1434 void TabStrip::GetAccessibleState(ui::AccessibleViewState* state) { | 1458 void TabStrip::GetAccessibleState(ui::AccessibleViewState* state) { |
1435 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; | 1459 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST; |
1436 } | 1460 } |
1437 | 1461 |
1438 views::View* TabStrip::GetEventHandlerForRect(const gfx::Rect& rect) { | 1462 views::View* TabStrip::GetEventHandlerForRect(const gfx::Rect& rect) { |
1439 if (!views::UsePointBasedTargeting(rect)) | 1463 if (!views::UsePointBasedTargeting(rect)) |
(...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2425 } | 2449 } |
2426 | 2450 |
2427 // TabStrip::DropInfo ---------------------------------------------------------- | 2451 // TabStrip::DropInfo ---------------------------------------------------------- |
2428 | 2452 |
2429 TabStrip::DropInfo::DropInfo(int drop_index, | 2453 TabStrip::DropInfo::DropInfo(int drop_index, |
2430 bool drop_before, | 2454 bool drop_before, |
2431 bool point_down, | 2455 bool point_down, |
2432 views::Widget* context) | 2456 views::Widget* context) |
2433 : drop_index(drop_index), | 2457 : drop_index(drop_index), |
2434 drop_before(drop_before), | 2458 drop_before(drop_before), |
2435 point_down(point_down) { | 2459 point_down(point_down), |
2460 file_supported(true) { | |
sky
2013/11/26 00:12:29
Is initializing to true really the right thing? Wh
michaelpg
2013/11/26 04:50:13
I would rather we try to open it even if it means
| |
2436 arrow_view = new views::ImageView; | 2461 arrow_view = new views::ImageView; |
2437 arrow_view->SetImage(GetDropArrowImage(point_down)); | 2462 arrow_view->SetImage(GetDropArrowImage(point_down)); |
2438 | 2463 |
2439 arrow_window = new views::Widget; | 2464 arrow_window = new views::Widget; |
2440 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); | 2465 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
2441 params.keep_on_top = true; | 2466 params.keep_on_top = true; |
2442 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 2467 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
2443 params.accept_events = false; | 2468 params.accept_events = false; |
2444 params.can_activate = false; | 2469 params.can_activate = false; |
2445 params.bounds = gfx::Rect(drop_indicator_width, drop_indicator_height); | 2470 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) | 2768 #if defined(USE_AURA) |
2744 return chrome::GetHostDesktopTypeForNativeView( | 2769 return chrome::GetHostDesktopTypeForNativeView( |
2745 GetWidget()->GetNativeView()) == chrome::HOST_DESKTOP_TYPE_ASH; | 2770 GetWidget()->GetNativeView()) == chrome::HOST_DESKTOP_TYPE_ASH; |
2746 #else | 2771 #else |
2747 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) | 2772 if (ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) |
2748 return false; | 2773 return false; |
2749 #endif | 2774 #endif |
2750 | 2775 |
2751 return true; | 2776 return true; |
2752 } | 2777 } |
OLD | NEW |