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/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/debug/alias.h" | 10 #include "base/debug/alias.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 //////////////////////////////////////////////////////////////////////////////// | 40 //////////////////////////////////////////////////////////////////////////////// |
41 // TabCloseButton | 41 // TabCloseButton |
42 // | 42 // |
43 // This is a Button subclass that causes middle clicks to be forwarded to the | 43 // This is a Button subclass that causes middle clicks to be forwarded to the |
44 // parent View by explicitly not handling them in OnMousePressed. | 44 // parent View by explicitly not handling them in OnMousePressed. |
45 class BaseTab::TabCloseButton : public views::ImageButton { | 45 class BaseTab::TabCloseButton : public views::ImageButton { |
46 public: | 46 public: |
47 explicit TabCloseButton(BaseTab* tab) : views::ImageButton(tab), tab_(tab) {} | 47 explicit TabCloseButton(BaseTab* tab) : views::ImageButton(tab), tab_(tab) {} |
48 virtual ~TabCloseButton() {} | 48 virtual ~TabCloseButton() {} |
49 | 49 |
50 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE { | 50 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE { |
51 if (tab_->controller()) | 51 if (tab_->controller()) |
52 tab_->controller()->OnMouseEventInTab(this, event); | 52 tab_->controller()->OnMouseEventInTab(this, event); |
53 | 53 |
54 bool handled = ImageButton::OnMousePressed(event); | 54 bool handled = ImageButton::OnMousePressed(event); |
55 // Explicitly mark midle-mouse clicks as non-handled to ensure the tab | 55 // Explicitly mark midle-mouse clicks as non-handled to ensure the tab |
56 // sees them. | 56 // sees them. |
57 return event.IsOnlyMiddleMouseButton() ? false : handled; | 57 return event.IsOnlyMiddleMouseButton() ? false : handled; |
58 } | 58 } |
59 | 59 |
60 // We need to let the parent know about mouse state so that it | 60 // We need to let the parent know about mouse state so that it |
61 // can highlight itself appropriately. Note that Exit events | 61 // can highlight itself appropriately. Note that Exit events |
62 // fire before Enter events, so this works. | 62 // fire before Enter events, so this works. |
63 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE { | 63 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE { |
64 CustomButton::OnMouseEntered(event); | 64 CustomButton::OnMouseEntered(event); |
65 parent()->OnMouseEntered(event); | 65 parent()->OnMouseEntered(event); |
66 } | 66 } |
67 | 67 |
68 virtual void OnMouseMoved(const views::MouseEvent& event) OVERRIDE { | 68 virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE { |
69 if (tab_->controller()) | 69 if (tab_->controller()) |
70 tab_->controller()->OnMouseEventInTab(this, event); | 70 tab_->controller()->OnMouseEventInTab(this, event); |
71 CustomButton::OnMouseMoved(event); | 71 CustomButton::OnMouseMoved(event); |
72 } | 72 } |
73 | 73 |
74 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE { | 74 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE { |
75 if (tab_->controller()) | 75 if (tab_->controller()) |
76 tab_->controller()->OnMouseEventInTab(this, event); | 76 tab_->controller()->OnMouseEventInTab(this, event); |
77 CustomButton::OnMouseReleased(event); | 77 CustomButton::OnMouseReleased(event); |
78 } | 78 } |
79 | 79 |
80 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE { | 80 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE { |
81 CustomButton::OnMouseExited(event); | 81 CustomButton::OnMouseExited(event); |
82 parent()->OnMouseExited(event); | 82 parent()->OnMouseExited(event); |
83 } | 83 } |
84 | 84 |
85 virtual ui::GestureStatus OnGestureEvent( | 85 virtual ui::GestureStatus OnGestureEvent( |
86 const views::GestureEvent& event) OVERRIDE { | 86 const views::GestureEvent& event) OVERRIDE { |
87 // Consume all gesture events here so that the parent (BaseTab) does not | 87 // Consume all gesture events here so that the parent (BaseTab) does not |
88 // start consuming gestures. | 88 // start consuming gestures. |
89 ImageButton::OnGestureEvent(event); | 89 ImageButton::OnGestureEvent(event); |
90 return ui::GESTURE_STATUS_CONSUMED; | 90 return ui::GESTURE_STATUS_CONSUMED; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 295 |
296 bool BaseTab::IsSelected() const { | 296 bool BaseTab::IsSelected() const { |
297 return controller() ? controller()->IsTabSelected(this) : true; | 297 return controller() ? controller()->IsTabSelected(this) : true; |
298 } | 298 } |
299 | 299 |
300 ui::ThemeProvider* BaseTab::GetThemeProvider() const { | 300 ui::ThemeProvider* BaseTab::GetThemeProvider() const { |
301 ui::ThemeProvider* tp = View::GetThemeProvider(); | 301 ui::ThemeProvider* tp = View::GetThemeProvider(); |
302 return tp ? tp : theme_provider_; | 302 return tp ? tp : theme_provider_; |
303 } | 303 } |
304 | 304 |
305 bool BaseTab::OnMousePressed(const views::MouseEvent& event) { | 305 bool BaseTab::OnMousePressed(const ui::MouseEvent& event) { |
306 if (!controller()) | 306 if (!controller()) |
307 return false; | 307 return false; |
308 | 308 |
309 controller()->OnMouseEventInTab(this, event); | 309 controller()->OnMouseEventInTab(this, event); |
310 | 310 |
311 // Allow a right click from touch to drag, which corresponds to a long click. | 311 // Allow a right click from touch to drag, which corresponds to a long click. |
312 if (event.IsOnlyLeftMouseButton() || | 312 if (event.IsOnlyLeftMouseButton() || |
313 (event.IsOnlyRightMouseButton() && event.flags() & ui::EF_FROM_TOUCH)) { | 313 (event.IsOnlyRightMouseButton() && event.flags() & ui::EF_FROM_TOUCH)) { |
314 TabStripSelectionModel original_selection; | 314 TabStripSelectionModel original_selection; |
315 original_selection.Copy(controller()->GetSelectionModel()); | 315 original_selection.Copy(controller()->GetSelectionModel()); |
(...skipping 14 matching lines...) Expand all Loading... |
330 controller()->ClickActiveTab(this); | 330 controller()->ClickActiveTab(this); |
331 } | 331 } |
332 } else if (!IsSelected()) { | 332 } else if (!IsSelected()) { |
333 controller()->SelectTab(this); | 333 controller()->SelectTab(this); |
334 } | 334 } |
335 controller()->MaybeStartDrag(this, event, original_selection); | 335 controller()->MaybeStartDrag(this, event, original_selection); |
336 } | 336 } |
337 return true; | 337 return true; |
338 } | 338 } |
339 | 339 |
340 bool BaseTab::OnMouseDragged(const views::MouseEvent& event) { | 340 bool BaseTab::OnMouseDragged(const ui::MouseEvent& event) { |
341 if (controller()) | 341 if (controller()) |
342 controller()->ContinueDrag(this, event.location()); | 342 controller()->ContinueDrag(this, event.location()); |
343 return true; | 343 return true; |
344 } | 344 } |
345 | 345 |
346 void BaseTab::OnMouseReleased(const views::MouseEvent& event) { | 346 void BaseTab::OnMouseReleased(const ui::MouseEvent& event) { |
347 if (!controller()) | 347 if (!controller()) |
348 return; | 348 return; |
349 | 349 |
350 controller()->OnMouseEventInTab(this, event); | 350 controller()->OnMouseEventInTab(this, event); |
351 | 351 |
352 // Notify the drag helper that we're done with any potential drag operations. | 352 // Notify the drag helper that we're done with any potential drag operations. |
353 // Clean up the drag helper, which is re-created on the next mouse press. | 353 // Clean up the drag helper, which is re-created on the next mouse press. |
354 // In some cases, ending the drag will schedule the tab for destruction; if | 354 // In some cases, ending the drag will schedule the tab for destruction; if |
355 // so, bail immediately, since our members are already dead and we shouldn't | 355 // so, bail immediately, since our members are already dead and we shouldn't |
356 // do anything else except drop the tab where it is. | 356 // do anything else except drop the tab where it is. |
(...skipping 22 matching lines...) Expand all Loading... |
379 // selected. | 379 // selected. |
380 controller()->SelectTab(this); | 380 controller()->SelectTab(this); |
381 } | 381 } |
382 } | 382 } |
383 | 383 |
384 void BaseTab::OnMouseCaptureLost() { | 384 void BaseTab::OnMouseCaptureLost() { |
385 if (controller()) | 385 if (controller()) |
386 controller()->EndDrag(true); | 386 controller()->EndDrag(true); |
387 } | 387 } |
388 | 388 |
389 void BaseTab::OnMouseEntered(const views::MouseEvent& event) { | 389 void BaseTab::OnMouseEntered(const ui::MouseEvent& event) { |
390 hover_controller_.Show(); | 390 hover_controller_.Show(); |
391 } | 391 } |
392 | 392 |
393 void BaseTab::OnMouseMoved(const views::MouseEvent& event) { | 393 void BaseTab::OnMouseMoved(const ui::MouseEvent& event) { |
394 if (controller()) | 394 if (controller()) |
395 controller()->OnMouseEventInTab(this, event); | 395 controller()->OnMouseEventInTab(this, event); |
396 } | 396 } |
397 | 397 |
398 void BaseTab::OnMouseExited(const views::MouseEvent& event) { | 398 void BaseTab::OnMouseExited(const ui::MouseEvent& event) { |
399 hover_controller_.Hide(); | 399 hover_controller_.Hide(); |
400 } | 400 } |
401 | 401 |
402 ui::GestureStatus BaseTab::OnGestureEvent(const views::GestureEvent& event) { | 402 ui::GestureStatus BaseTab::OnGestureEvent(const views::GestureEvent& event) { |
403 if (!controller()) | 403 if (!controller()) |
404 return ui::GESTURE_STATUS_CONSUMED; | 404 return ui::GESTURE_STATUS_CONSUMED; |
405 | 405 |
406 switch (event.type()) { | 406 switch (event.type()) { |
407 case ui::ET_GESTURE_BEGIN: { | 407 case ui::ET_GESTURE_BEGIN: { |
408 if (event.details().touch_points() != 1) | 408 if (event.details().touch_points() != 1) |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 // static | 639 // static |
640 void BaseTab::InitResources() { | 640 void BaseTab::InitResources() { |
641 static bool initialized = false; | 641 static bool initialized = false; |
642 if (!initialized) { | 642 if (!initialized) { |
643 initialized = true; | 643 initialized = true; |
644 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 644 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
645 font_ = new gfx::Font(rb.GetFont(ui::ResourceBundle::BaseFont)); | 645 font_ = new gfx::Font(rb.GetFont(ui::ResourceBundle::BaseFont)); |
646 font_height_ = font_->GetHeight(); | 646 font_height_ = font_->GetHeight(); |
647 } | 647 } |
648 } | 648 } |
OLD | NEW |