| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base_tab.h" | 5 #include "chrome/browser/ui/views/tabs/base_tab.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 } | 304 } |
| 305 return true; | 305 return true; |
| 306 } | 306 } |
| 307 | 307 |
| 308 bool BaseTab::OnMouseDragged(const views::MouseEvent& event) { | 308 bool BaseTab::OnMouseDragged(const views::MouseEvent& event) { |
| 309 if (controller()) | 309 if (controller()) |
| 310 controller()->ContinueDrag(event); | 310 controller()->ContinueDrag(event); |
| 311 return true; | 311 return true; |
| 312 } | 312 } |
| 313 | 313 |
| 314 void BaseTab::OnMouseReleased(const views::MouseEvent& event, bool canceled) { | 314 void BaseTab::OnMouseReleased(const views::MouseEvent& event) { |
| 315 if (!controller()) | 315 if (!controller()) |
| 316 return; | 316 return; |
| 317 | 317 |
| 318 // Notify the drag helper that we're done with any potential drag operations. | 318 // Notify the drag helper that we're done with any potential drag operations. |
| 319 // Clean up the drag helper, which is re-created on the next mouse press. | 319 // Clean up the drag helper, which is re-created on the next mouse press. |
| 320 // In some cases, ending the drag will schedule the tab for destruction; if | 320 // In some cases, ending the drag will schedule the tab for destruction; if |
| 321 // so, bail immediately, since our members are already dead and we shouldn't | 321 // so, bail immediately, since our members are already dead and we shouldn't |
| 322 // do anything else except drop the tab where it is. | 322 // do anything else except drop the tab where it is. |
| 323 if (controller()->EndDrag(canceled)) | 323 if (controller()->EndDrag(false)) |
| 324 return; | 324 return; |
| 325 | 325 |
| 326 // Close tab on middle click, but only if the button is released over the tab | 326 // Close tab on middle click, but only if the button is released over the tab |
| 327 // (normal windows behavior is to discard presses of a UI element where the | 327 // (normal windows behavior is to discard presses of a UI element where the |
| 328 // releases happen off the element). | 328 // releases happen off the element). |
| 329 if (event.IsMiddleMouseButton()) { | 329 if (event.IsMiddleMouseButton()) { |
| 330 if (HitTest(event.location())) { | 330 if (HitTest(event.location())) { |
| 331 controller()->CloseTab(this); | 331 controller()->CloseTab(this); |
| 332 } else if (closing_) { | 332 } else if (closing_) { |
| 333 // We're animating closed and a middle mouse button was pushed on us but | 333 // We're animating closed and a middle mouse button was pushed on us but |
| 334 // we don't contain the mouse anymore. We assume the user is clicking | 334 // we don't contain the mouse anymore. We assume the user is clicking |
| 335 // quicker than the animation and we should close the tab that falls under | 335 // quicker than the animation and we should close the tab that falls under |
| 336 // the mouse. | 336 // the mouse. |
| 337 BaseTab* closest_tab = controller()->GetTabAt(this, event.location()); | 337 BaseTab* closest_tab = controller()->GetTabAt(this, event.location()); |
| 338 if (closest_tab) | 338 if (closest_tab) |
| 339 controller()->CloseTab(closest_tab); | 339 controller()->CloseTab(closest_tab); |
| 340 } | 340 } |
| 341 } else if (event.IsOnlyLeftMouseButton() && !event.IsShiftDown() && | 341 } else if (event.IsOnlyLeftMouseButton() && !event.IsShiftDown() && |
| 342 !event.IsControlDown()) { | 342 !event.IsControlDown()) { |
| 343 // If the tab was already selected mouse pressed doesn't change the | 343 // If the tab was already selected mouse pressed doesn't change the |
| 344 // selection. Reset it now to handle the case where multiple tabs were | 344 // selection. Reset it now to handle the case where multiple tabs were |
| 345 // selected. | 345 // selected. |
| 346 controller()->SelectTab(this); | 346 controller()->SelectTab(this); |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 | 349 |
| 350 void BaseTab::OnMouseCaptureLost() { |
| 351 if (controller()) |
| 352 controller()->EndDrag(true); |
| 353 } |
| 354 |
| 350 void BaseTab::OnMouseEntered(const views::MouseEvent& event) { | 355 void BaseTab::OnMouseEntered(const views::MouseEvent& event) { |
| 351 if (!hover_animation_.get()) { | 356 if (!hover_animation_.get()) { |
| 352 hover_animation_.reset(new ui::SlideAnimation(this)); | 357 hover_animation_.reset(new ui::SlideAnimation(this)); |
| 353 hover_animation_->SetContainer(animation_container_.get()); | 358 hover_animation_->SetContainer(animation_container_.get()); |
| 354 hover_animation_->SetSlideDuration(kHoverDurationMs); | 359 hover_animation_->SetSlideDuration(kHoverDurationMs); |
| 355 } | 360 } |
| 356 hover_animation_->SetTweenType(ui::Tween::EASE_OUT); | 361 hover_animation_->SetTweenType(ui::Tween::EASE_OUT); |
| 357 hover_animation_->Show(); | 362 hover_animation_->Show(); |
| 358 } | 363 } |
| 359 | 364 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 // static | 573 // static |
| 569 void BaseTab::InitResources() { | 574 void BaseTab::InitResources() { |
| 570 static bool initialized = false; | 575 static bool initialized = false; |
| 571 if (!initialized) { | 576 if (!initialized) { |
| 572 initialized = true; | 577 initialized = true; |
| 573 font_ = new gfx::Font( | 578 font_ = new gfx::Font( |
| 574 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont)); | 579 ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont)); |
| 575 font_height_ = font_->GetHeight(); | 580 font_height_ = font_->GetHeight(); |
| 576 } | 581 } |
| 577 } | 582 } |
| OLD | NEW |