| 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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 // image. | 287 // image. |
| 288 void set_background_offset(const gfx::Point& offset) { | 288 void set_background_offset(const gfx::Point& offset) { |
| 289 background_offset_ = offset; | 289 background_offset_ = offset; |
| 290 } | 290 } |
| 291 | 291 |
| 292 protected: | 292 protected: |
| 293 // Overridden from views::View: | 293 // Overridden from views::View: |
| 294 virtual bool HasHitTestMask() const OVERRIDE; | 294 virtual bool HasHitTestMask() const OVERRIDE; |
| 295 virtual void GetHitTestMask(gfx::Path* path) const OVERRIDE; | 295 virtual void GetHitTestMask(gfx::Path* path) const OVERRIDE; |
| 296 #if defined(OS_WIN) && !defined(USE_AURA) | 296 #if defined(OS_WIN) && !defined(USE_AURA) |
| 297 void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; | 297 void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; |
| 298 #endif | 298 #endif |
| 299 virtual ui::GestureStatus OnGestureEvent( | 299 virtual ui::GestureStatus OnGestureEvent( |
| 300 const views::GestureEvent& event) OVERRIDE; | 300 const views::GestureEvent& event) OVERRIDE; |
| 301 void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 301 void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
| 302 | 302 |
| 303 private: | 303 private: |
| 304 bool ShouldUseNativeFrame() const; | 304 bool ShouldUseNativeFrame() const; |
| 305 gfx::ImageSkia GetBackgroundImage(views::CustomButton::ButtonState state, | 305 gfx::ImageSkia GetBackgroundImage(views::CustomButton::ButtonState state, |
| 306 ui::ScaleFactor scale_factor) const; | 306 ui::ScaleFactor scale_factor) const; |
| 307 gfx::ImageSkia GetImageForState(views::CustomButton::ButtonState state, | 307 gfx::ImageSkia GetImageForState(views::CustomButton::ButtonState state, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 path->lineTo(w - 4, 4); | 346 path->lineTo(w - 4, 4); |
| 347 path->lineTo(w, 16); | 347 path->lineTo(w, 16); |
| 348 path->lineTo(w - 1, 17); | 348 path->lineTo(w - 1, 17); |
| 349 path->lineTo(7, 17); | 349 path->lineTo(7, 17); |
| 350 path->lineTo(4, 13); | 350 path->lineTo(4, 13); |
| 351 path->lineTo(0, 1); | 351 path->lineTo(0, 1); |
| 352 path->close(); | 352 path->close(); |
| 353 } | 353 } |
| 354 | 354 |
| 355 #if defined(OS_WIN) && !defined(USE_AURA) | 355 #if defined(OS_WIN) && !defined(USE_AURA) |
| 356 void NewTabButton::OnMouseReleased(const views::MouseEvent& event) { | 356 void NewTabButton::OnMouseReleased(const ui::MouseEvent& event) { |
| 357 if (event.IsOnlyRightMouseButton()) { | 357 if (event.IsOnlyRightMouseButton()) { |
| 358 gfx::Point point(event.x(), event.y()); | 358 gfx::Point point(event.x(), event.y()); |
| 359 views::View::ConvertPointToScreen(this, &point); | 359 views::View::ConvertPointToScreen(this, &point); |
| 360 ui::ShowSystemMenu(GetWidget()->GetNativeView(), point.x(), point.y()); | 360 ui::ShowSystemMenu(GetWidget()->GetNativeView(), point.x(), point.y()); |
| 361 SetState(BS_NORMAL); | 361 SetState(BS_NORMAL); |
| 362 return; | 362 return; |
| 363 } | 363 } |
| 364 views::ImageButton::OnMouseReleased(event); | 364 views::ImageButton::OnMouseReleased(event); |
| 365 } | 365 } |
| 366 #endif | 366 #endif |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 | 549 |
| 550 views::Widget* widget = tabstrip_->GetWidget(); | 550 views::Widget* widget = tabstrip_->GetWidget(); |
| 551 // This can be null during shutdown. See http://crbug.com/42737. | 551 // This can be null during shutdown. See http://crbug.com/42737. |
| 552 if (!widget) | 552 if (!widget) |
| 553 return; | 553 return; |
| 554 | 554 |
| 555 widget->ResetLastMouseMoveFlag(); | 555 widget->ResetLastMouseMoveFlag(); |
| 556 gfx::Point position = gfx::Screen::GetCursorScreenPoint(); | 556 gfx::Point position = gfx::Screen::GetCursorScreenPoint(); |
| 557 views::View* root_view = widget->GetRootView(); | 557 views::View* root_view = widget->GetRootView(); |
| 558 views::View::ConvertPointFromScreen(root_view, &position); | 558 views::View::ConvertPointFromScreen(root_view, &position); |
| 559 views::MouseEvent mouse_event( | 559 ui::MouseEvent mouse_event(ui::ET_MOUSE_MOVED, |
| 560 ui::ET_MOUSE_MOVED, position.x(), position.y(), ui::EF_IS_SYNTHESIZED); | 560 position, position, |
| 561 ui::EF_IS_SYNTHESIZED); |
| 561 root_view->OnMouseMoved(mouse_event); | 562 root_view->OnMouseMoved(mouse_event); |
| 562 } | 563 } |
| 563 | 564 |
| 564 /////////////////////////////////////////////////////////////////////////////// | 565 /////////////////////////////////////////////////////////////////////////////// |
| 565 // TabStrip, public: | 566 // TabStrip, public: |
| 566 | 567 |
| 567 // static | 568 // static |
| 568 const char TabStrip::kViewClassName[] = "TabStrip"; | 569 const char TabStrip::kViewClassName[] = "TabStrip"; |
| 569 | 570 |
| 570 // static | 571 // static |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 // Use MOVE_VISIBILE_TABS in the following conditions: | 1017 // Use MOVE_VISIBILE_TABS in the following conditions: |
| 1017 // . Mouse event generated from touch and the left button is down (the right | 1018 // . Mouse event generated from touch and the left button is down (the right |
| 1018 // button corresponds to a long press, which we want to reorder). | 1019 // button corresponds to a long press, which we want to reorder). |
| 1019 // . Gesture begin and control key isn't down. | 1020 // . Gesture begin and control key isn't down. |
| 1020 // . Real mouse event and control is down. This is mostly for testing. | 1021 // . Real mouse event and control is down. This is mostly for testing. |
| 1021 DCHECK(event.type() == ui::ET_MOUSE_PRESSED || | 1022 DCHECK(event.type() == ui::ET_MOUSE_PRESSED || |
| 1022 event.type() == ui::ET_GESTURE_BEGIN); | 1023 event.type() == ui::ET_GESTURE_BEGIN); |
| 1023 if (adjust_layout_ && | 1024 if (adjust_layout_ && |
| 1024 ((event.type() == ui::ET_MOUSE_PRESSED && | 1025 ((event.type() == ui::ET_MOUSE_PRESSED && |
| 1025 (((event.flags() & ui::EF_FROM_TOUCH) && | 1026 (((event.flags() & ui::EF_FROM_TOUCH) && |
| 1026 static_cast<const views::MouseEvent&>(event).IsLeftMouseButton()) || | 1027 static_cast<const ui::MouseEvent&>(event).IsLeftMouseButton()) || |
| 1027 (!(event.flags() & ui::EF_FROM_TOUCH) && | 1028 (!(event.flags() & ui::EF_FROM_TOUCH) && |
| 1028 static_cast<const views::MouseEvent&>(event).IsControlDown()))) || | 1029 static_cast<const ui::MouseEvent&>(event).IsControlDown()))) || |
| 1029 (event.type() == ui::ET_GESTURE_BEGIN && !event.IsControlDown()))) { | 1030 (event.type() == ui::ET_GESTURE_BEGIN && !event.IsControlDown()))) { |
| 1030 move_behavior = TabDragController::MOVE_VISIBILE_TABS; | 1031 move_behavior = TabDragController::MOVE_VISIBILE_TABS; |
| 1031 } | 1032 } |
| 1032 #if defined(OS_WIN) | 1033 #if defined(OS_WIN) |
| 1033 // It doesn't make sense to drag tabs out on metro. | 1034 // It doesn't make sense to drag tabs out on metro. |
| 1034 if (base::win::IsMetroProcess()) | 1035 if (base::win::IsMetroProcess()) |
| 1035 detach_behavior = TabDragController::NOT_DETACHABLE; | 1036 detach_behavior = TabDragController::NOT_DETACHABLE; |
| 1036 #endif | 1037 #endif |
| 1037 // Gestures don't automatically do a capture. We don't allow multiple drags at | 1038 // Gestures don't automatically do a capture. We don't allow multiple drags at |
| 1038 // the same time, so we explicitly capture. | 1039 // the same time, so we explicitly capture. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1077 } | 1078 } |
| 1078 | 1079 |
| 1079 void TabStrip::ClickActiveTab(const BaseTab* tab) const { | 1080 void TabStrip::ClickActiveTab(const BaseTab* tab) const { |
| 1080 DCHECK(IsActiveTab(tab)); | 1081 DCHECK(IsActiveTab(tab)); |
| 1081 int index = GetModelIndexOfBaseTab(tab); | 1082 int index = GetModelIndexOfBaseTab(tab); |
| 1082 if (controller() && IsValidModelIndex(index)) | 1083 if (controller() && IsValidModelIndex(index)) |
| 1083 controller()->ClickActiveTab(index); | 1084 controller()->ClickActiveTab(index); |
| 1084 } | 1085 } |
| 1085 | 1086 |
| 1086 void TabStrip::OnMouseEventInTab(views::View* source, | 1087 void TabStrip::OnMouseEventInTab(views::View* source, |
| 1087 const views::MouseEvent& event) { | 1088 const ui::MouseEvent& event) { |
| 1088 UpdateLayoutTypeFromMouseEvent(source, event); | 1089 UpdateLayoutTypeFromMouseEvent(source, event); |
| 1089 } | 1090 } |
| 1090 | 1091 |
| 1091 bool TabStrip::ShouldPaintTab(const BaseTab* tab, gfx::Rect* clip) { | 1092 bool TabStrip::ShouldPaintTab(const BaseTab* tab, gfx::Rect* clip) { |
| 1092 // Only touch layout needs to restrict the clip. | 1093 // Only touch layout needs to restrict the clip. |
| 1093 if (!touch_layout_.get()) | 1094 if (!touch_layout_.get()) |
| 1094 return true; | 1095 return true; |
| 1095 | 1096 |
| 1096 int index = GetModelIndexOfBaseTab(tab); | 1097 int index = GetModelIndexOfBaseTab(tab); |
| 1097 if (index == -1) | 1098 if (index == -1) |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 return tab_at(index); | 1377 return tab_at(index); |
| 1377 } else { | 1378 } else { |
| 1378 return NULL; | 1379 return NULL; |
| 1379 } | 1380 } |
| 1380 } | 1381 } |
| 1381 } | 1382 } |
| 1382 | 1383 |
| 1383 return View::GetViewByID(view_id); | 1384 return View::GetViewByID(view_id); |
| 1384 } | 1385 } |
| 1385 | 1386 |
| 1386 bool TabStrip::OnMousePressed(const views::MouseEvent& event) { | 1387 bool TabStrip::OnMousePressed(const ui::MouseEvent& event) { |
| 1387 UpdateLayoutTypeFromMouseEvent(this, event); | 1388 UpdateLayoutTypeFromMouseEvent(this, event); |
| 1388 // We can't return true here, else clicking in an empty area won't drag the | 1389 // We can't return true here, else clicking in an empty area won't drag the |
| 1389 // window. | 1390 // window. |
| 1390 return false; | 1391 return false; |
| 1391 } | 1392 } |
| 1392 | 1393 |
| 1393 bool TabStrip::OnMouseDragged(const views::MouseEvent& event) { | 1394 bool TabStrip::OnMouseDragged(const ui::MouseEvent& event) { |
| 1394 ContinueDrag(this, event.location()); | 1395 ContinueDrag(this, event.location()); |
| 1395 return true; | 1396 return true; |
| 1396 } | 1397 } |
| 1397 | 1398 |
| 1398 void TabStrip::OnMouseReleased(const views::MouseEvent& event) { | 1399 void TabStrip::OnMouseReleased(const ui::MouseEvent& event) { |
| 1399 EndDrag(false); | 1400 EndDrag(false); |
| 1400 UpdateLayoutTypeFromMouseEvent(this, event); | 1401 UpdateLayoutTypeFromMouseEvent(this, event); |
| 1401 } | 1402 } |
| 1402 | 1403 |
| 1403 void TabStrip::OnMouseCaptureLost() { | 1404 void TabStrip::OnMouseCaptureLost() { |
| 1404 EndDrag(true); | 1405 EndDrag(true); |
| 1405 } | 1406 } |
| 1406 | 1407 |
| 1407 void TabStrip::OnMouseMoved(const views::MouseEvent& event) { | 1408 void TabStrip::OnMouseMoved(const ui::MouseEvent& event) { |
| 1408 UpdateLayoutTypeFromMouseEvent(this, event); | 1409 UpdateLayoutTypeFromMouseEvent(this, event); |
| 1409 } | 1410 } |
| 1410 | 1411 |
| 1411 ui::GestureStatus TabStrip::OnGestureEvent( | 1412 ui::GestureStatus TabStrip::OnGestureEvent( |
| 1412 const views::GestureEvent& event) { | 1413 const views::GestureEvent& event) { |
| 1413 switch (event.type()) { | 1414 switch (event.type()) { |
| 1414 case ui::ET_GESTURE_END: | 1415 case ui::ET_GESTURE_END: |
| 1415 EndDrag(false); | 1416 EndDrag(false); |
| 1416 if (adjust_layout_ && ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) { | 1417 if (adjust_layout_ && ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) { |
| 1417 SetLayoutType(TAB_STRIP_LAYOUT_STACKED, true); | 1418 SetLayoutType(TAB_STRIP_LAYOUT_STACKED, true); |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1790 return; | 1791 return; |
| 1791 | 1792 |
| 1792 const std::vector<BaseTab*>& tabs = tabs_closing_map_[index]; | 1793 const std::vector<BaseTab*>& tabs = tabs_closing_map_[index]; |
| 1793 for (std::vector<BaseTab*>::const_reverse_iterator i(tabs.rbegin()); | 1794 for (std::vector<BaseTab*>::const_reverse_iterator i(tabs.rbegin()); |
| 1794 i != tabs.rend(); ++i) { | 1795 i != tabs.rend(); ++i) { |
| 1795 (*i)->Paint(canvas); | 1796 (*i)->Paint(canvas); |
| 1796 } | 1797 } |
| 1797 } | 1798 } |
| 1798 | 1799 |
| 1799 void TabStrip::UpdateLayoutTypeFromMouseEvent(views::View* source, | 1800 void TabStrip::UpdateLayoutTypeFromMouseEvent(views::View* source, |
| 1800 const views::MouseEvent& event) { | 1801 const ui::MouseEvent& event) { |
| 1801 if (!adjust_layout_ || ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) | 1802 if (!adjust_layout_ || ui::GetDisplayLayout() != ui::LAYOUT_TOUCH) |
| 1802 return; | 1803 return; |
| 1803 | 1804 |
| 1804 // The following code attempts to switch to TAB_STRIP_LAYOUT_SHRINK when the | 1805 // The following code attempts to switch to TAB_STRIP_LAYOUT_SHRINK when the |
| 1805 // mouse is used, and TAB_STRIP_LAYOUT_STACKED when a touch device is | 1806 // mouse is used, and TAB_STRIP_LAYOUT_STACKED when a touch device is |
| 1806 // used. This is made problematic by windows generating mouse move events that | 1807 // used. This is made problematic by windows generating mouse move events that |
| 1807 // do not clearly indicate the move is the result of a touch device. This | 1808 // do not clearly indicate the move is the result of a touch device. This |
| 1808 // assumes a real mouse is used if |kMouseMoveCountBeforeConsiderReal| mouse | 1809 // assumes a real mouse is used if |kMouseMoveCountBeforeConsiderReal| mouse |
| 1809 // move events are received within the time window |kMouseMoveTimeMS|. | 1810 // move events are received within the time window |kMouseMoveTimeMS|. |
| 1810 // At the time we get a mouse press we know whether its from a touch device | 1811 // At the time we get a mouse press we know whether its from a touch device |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2360 | 2361 |
| 2361 int mini_tab_count = GetMiniTabCount(); | 2362 int mini_tab_count = GetMiniTabCount(); |
| 2362 int normal_count = tab_count() - mini_tab_count; | 2363 int normal_count = tab_count() - mini_tab_count; |
| 2363 if (normal_count <= 1 || normal_count == mini_tab_count) | 2364 if (normal_count <= 1 || normal_count == mini_tab_count) |
| 2364 return false; | 2365 return false; |
| 2365 int x = GetStartXForNormalTabs(); | 2366 int x = GetStartXForNormalTabs(); |
| 2366 int available_width = width() - x - new_tab_button_width(); | 2367 int available_width = width() - x - new_tab_button_width(); |
| 2367 return (Tab::GetTouchWidth() * normal_count + | 2368 return (Tab::GetTouchWidth() * normal_count + |
| 2368 tab_h_offset() * (normal_count - 1)) > available_width; | 2369 tab_h_offset() * (normal_count - 1)) > available_width; |
| 2369 } | 2370 } |
| OLD | NEW |