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