| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/gtk/tabs/tab_button_gtk.h" | |
| 6 | |
| 7 TabButtonGtk::TabButtonGtk(Delegate* delegate) | |
| 8 : state_(BS_NORMAL), | |
| 9 mouse_pressed_(false), | |
| 10 delegate_(delegate) { | |
| 11 } | |
| 12 | |
| 13 TabButtonGtk::~TabButtonGtk() { | |
| 14 } | |
| 15 | |
| 16 bool TabButtonGtk::IsPointInBounds(const gfx::Point& point) { | |
| 17 GdkRegion* region = delegate_->MakeRegionForButton(this); | |
| 18 if (!region) | |
| 19 return bounds_.Contains(point); | |
| 20 | |
| 21 bool in_bounds = (gdk_region_point_in(region, point.x(), point.y()) == TRUE); | |
| 22 gdk_region_destroy(region); | |
| 23 return in_bounds; | |
| 24 } | |
| 25 | |
| 26 bool TabButtonGtk::OnMotionNotify(GdkEventMotion* event) { | |
| 27 ButtonState state; | |
| 28 | |
| 29 gfx::Point point(event->x, event->y); | |
| 30 if (IsPointInBounds(point)) { | |
| 31 if (mouse_pressed_) { | |
| 32 state = BS_PUSHED; | |
| 33 } else { | |
| 34 state = BS_HOT; | |
| 35 } | |
| 36 } else { | |
| 37 state = BS_NORMAL; | |
| 38 } | |
| 39 | |
| 40 bool need_redraw = (state_ != state); | |
| 41 state_ = state; | |
| 42 return need_redraw; | |
| 43 } | |
| 44 | |
| 45 bool TabButtonGtk::OnMousePress() { | |
| 46 if (state_ == BS_HOT) { | |
| 47 mouse_pressed_ = true; | |
| 48 state_ = BS_PUSHED; | |
| 49 return true; | |
| 50 } | |
| 51 | |
| 52 return false; | |
| 53 } | |
| 54 | |
| 55 void TabButtonGtk::OnMouseRelease() { | |
| 56 mouse_pressed_ = false; | |
| 57 | |
| 58 if (state_ == BS_PUSHED) { | |
| 59 delegate_->OnButtonActivate(this); | |
| 60 | |
| 61 // Jiggle the mouse so we re-highlight the Tab button. | |
| 62 HighlightTabButton(); | |
| 63 } | |
| 64 | |
| 65 state_ = BS_NORMAL; | |
| 66 } | |
| 67 | |
| 68 bool TabButtonGtk::OnLeaveNotify() { | |
| 69 bool paint = (state_ != BS_NORMAL); | |
| 70 state_ = BS_NORMAL; | |
| 71 return paint; | |
| 72 } | |
| 73 | |
| 74 void TabButtonGtk::Paint(ChromeCanvasPaint* canvas) { | |
| 75 canvas->DrawBitmapInt(images_[state_], bounds_.x(), bounds_.y()); | |
| 76 } | |
| 77 | |
| 78 void TabButtonGtk::SetImage(ButtonState state, SkBitmap* bitmap) { | |
| 79 images_[state] = bitmap ? *bitmap : SkBitmap(); | |
| 80 } | |
| 81 | |
| 82 void TabButtonGtk::HighlightTabButton() { | |
| 83 // Get default display and screen. | |
| 84 GdkDisplay* display = gdk_display_get_default(); | |
| 85 GdkScreen* screen = gdk_display_get_default_screen(display); | |
| 86 | |
| 87 // Get cursor position. | |
| 88 int x, y; | |
| 89 gdk_display_get_pointer(display, NULL, &x, &y, NULL); | |
| 90 | |
| 91 // Reset cusor position. | |
| 92 gdk_display_warp_pointer(display, screen, x, y); | |
| 93 } | |
| OLD | NEW |