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 28 matching lines...) Expand all Loading... |
39 #include "ui/gfx/animation/animation_container.h" | 39 #include "ui/gfx/animation/animation_container.h" |
40 #include "ui/gfx/animation/throb_animation.h" | 40 #include "ui/gfx/animation/throb_animation.h" |
41 #include "ui/gfx/canvas.h" | 41 #include "ui/gfx/canvas.h" |
42 #include "ui/gfx/display.h" | 42 #include "ui/gfx/display.h" |
43 #include "ui/gfx/image/image_skia.h" | 43 #include "ui/gfx/image/image_skia.h" |
44 #include "ui/gfx/image/image_skia_operations.h" | 44 #include "ui/gfx/image/image_skia_operations.h" |
45 #include "ui/gfx/path.h" | 45 #include "ui/gfx/path.h" |
46 #include "ui/gfx/rect_conversions.h" | 46 #include "ui/gfx/rect_conversions.h" |
47 #include "ui/gfx/screen.h" | 47 #include "ui/gfx/screen.h" |
48 #include "ui/gfx/size.h" | 48 #include "ui/gfx/size.h" |
| 49 #include "ui/gfx/skia_util.h" |
49 #include "ui/views/controls/image_view.h" | 50 #include "ui/views/controls/image_view.h" |
| 51 #include "ui/views/masked_targeter_delegate.h" |
50 #include "ui/views/mouse_watcher_view_host.h" | 52 #include "ui/views/mouse_watcher_view_host.h" |
51 #include "ui/views/rect_based_targeting_utils.h" | 53 #include "ui/views/rect_based_targeting_utils.h" |
52 #include "ui/views/view_model_utils.h" | 54 #include "ui/views/view_model_utils.h" |
53 #include "ui/views/widget/root_view.h" | 55 #include "ui/views/widget/root_view.h" |
54 #include "ui/views/widget/widget.h" | 56 #include "ui/views/widget/widget.h" |
55 #include "ui/views/window/non_client_view.h" | 57 #include "ui/views/window/non_client_view.h" |
56 | 58 |
57 #if defined(OS_WIN) | 59 #if defined(OS_WIN) |
58 #include "ui/gfx/win/hwnd_util.h" | 60 #include "ui/gfx/win/hwnd_util.h" |
59 #include "ui/views/widget/monitor_win.h" | 61 #include "ui/views/widget/monitor_win.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 224 } |
223 | 225 |
224 } // namespace | 226 } // namespace |
225 | 227 |
226 /////////////////////////////////////////////////////////////////////////////// | 228 /////////////////////////////////////////////////////////////////////////////// |
227 // NewTabButton | 229 // NewTabButton |
228 // | 230 // |
229 // A subclass of button that hit-tests to the shape of the new tab button and | 231 // A subclass of button that hit-tests to the shape of the new tab button and |
230 // does custom drawing. | 232 // does custom drawing. |
231 | 233 |
232 class NewTabButton : public views::ImageButton { | 234 class NewTabButton : public views::ImageButton, |
| 235 public views::MaskedTargeterDelegate { |
233 public: | 236 public: |
234 NewTabButton(TabStrip* tab_strip, views::ButtonListener* listener); | 237 NewTabButton(TabStrip* tab_strip, views::ButtonListener* listener); |
235 virtual ~NewTabButton(); | 238 virtual ~NewTabButton(); |
236 | 239 |
237 // Set the background offset used to match the background image to the frame | 240 // Set the background offset used to match the background image to the frame |
238 // image. | 241 // image. |
239 void set_background_offset(const gfx::Point& offset) { | 242 void set_background_offset(const gfx::Point& offset) { |
240 background_offset_ = offset; | 243 background_offset_ = offset; |
241 } | 244 } |
242 | 245 |
243 protected: | 246 protected: |
244 // Overridden from views::View: | 247 // views::View: |
245 virtual bool HasHitTestMask() const OVERRIDE; | |
246 virtual void GetHitTestMaskDeprecated(HitTestSource source, | |
247 gfx::Path* path) const OVERRIDE; | |
248 #if defined(OS_WIN) | 248 #if defined(OS_WIN) |
249 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | 249 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; |
250 #endif | 250 #endif |
251 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 251 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
252 | 252 |
253 // Overridden from ui::EventHandler: | 253 // ui::EventHandler: |
254 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 254 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
255 | 255 |
256 private: | 256 private: |
| 257 // views::MaskedTargeterDelegate: |
| 258 virtual bool GetHitTestMask(gfx::Path* mask) const OVERRIDE; |
| 259 |
257 bool ShouldWindowContentsBeTransparent() const; | 260 bool ShouldWindowContentsBeTransparent() const; |
258 gfx::ImageSkia GetBackgroundImage(views::CustomButton::ButtonState state, | 261 gfx::ImageSkia GetBackgroundImage(views::CustomButton::ButtonState state, |
259 float scale) const; | 262 float scale) const; |
260 gfx::ImageSkia GetImageForState(views::CustomButton::ButtonState state, | 263 gfx::ImageSkia GetImageForState(views::CustomButton::ButtonState state, |
261 float scale) const; | 264 float scale) const; |
262 gfx::ImageSkia GetImageForScale(float scale) const; | 265 gfx::ImageSkia GetImageForScale(float scale) const; |
263 | 266 |
264 // Tab strip that contains this button. | 267 // Tab strip that contains this button. |
265 TabStrip* tab_strip_; | 268 TabStrip* tab_strip_; |
266 | 269 |
(...skipping 14 matching lines...) Expand all Loading... |
281 set_triggerable_event_flags(triggerable_event_flags() | | 284 set_triggerable_event_flags(triggerable_event_flags() | |
282 ui::EF_MIDDLE_MOUSE_BUTTON); | 285 ui::EF_MIDDLE_MOUSE_BUTTON); |
283 #endif | 286 #endif |
284 } | 287 } |
285 | 288 |
286 NewTabButton::~NewTabButton() { | 289 NewTabButton::~NewTabButton() { |
287 if (destroyed_) | 290 if (destroyed_) |
288 *destroyed_ = true; | 291 *destroyed_ = true; |
289 } | 292 } |
290 | 293 |
291 bool NewTabButton::HasHitTestMask() const { | |
292 // When the button is sized to the top of the tab strip we want the user to | |
293 // be able to click on complete bounds, and so don't return a custom hit | |
294 // mask. | |
295 return !tab_strip_->SizeTabButtonToTopOfTabStrip(); | |
296 } | |
297 | |
298 void NewTabButton::GetHitTestMaskDeprecated(HitTestSource source, | |
299 gfx::Path* path) const { | |
300 DCHECK(path); | |
301 | |
302 SkScalar w = SkIntToScalar(width()); | |
303 SkScalar v_offset = SkIntToScalar(TabStrip::kNewTabButtonVerticalOffset); | |
304 | |
305 // These values are defined by the shape of the new tab image. Should that | |
306 // image ever change, these values will need to be updated. They're so | |
307 // custom it's not really worth defining constants for. | |
308 // These values are correct for regular and USE_ASH versions of the image. | |
309 path->moveTo(0, v_offset + 1); | |
310 path->lineTo(w - 7, v_offset + 1); | |
311 path->lineTo(w - 4, v_offset + 4); | |
312 path->lineTo(w, v_offset + 16); | |
313 path->lineTo(w - 1, v_offset + 17); | |
314 path->lineTo(7, v_offset + 17); | |
315 path->lineTo(4, v_offset + 13); | |
316 path->lineTo(0, v_offset + 1); | |
317 path->close(); | |
318 } | |
319 | |
320 #if defined(OS_WIN) | 294 #if defined(OS_WIN) |
321 void NewTabButton::OnMouseReleased(const ui::MouseEvent& event) { | 295 void NewTabButton::OnMouseReleased(const ui::MouseEvent& event) { |
322 if (event.IsOnlyRightMouseButton()) { | 296 if (event.IsOnlyRightMouseButton()) { |
323 gfx::Point point = event.location(); | 297 gfx::Point point = event.location(); |
324 views::View::ConvertPointToScreen(this, &point); | 298 views::View::ConvertPointToScreen(this, &point); |
325 bool destroyed = false; | 299 bool destroyed = false; |
326 destroyed_ = &destroyed; | 300 destroyed_ = &destroyed; |
327 gfx::ShowSystemMenuAtPoint(views::HWNDForView(this), point); | 301 gfx::ShowSystemMenuAtPoint(views::HWNDForView(this), point); |
328 if (destroyed) | 302 if (destroyed) |
329 return; | 303 return; |
(...skipping 11 matching lines...) Expand all Loading... |
341 canvas->DrawImageInt(image, 0, height() - image.height()); | 315 canvas->DrawImageInt(image, 0, height() - image.height()); |
342 } | 316 } |
343 | 317 |
344 void NewTabButton::OnGestureEvent(ui::GestureEvent* event) { | 318 void NewTabButton::OnGestureEvent(ui::GestureEvent* event) { |
345 // Consume all gesture events here so that the parent (Tab) does not | 319 // Consume all gesture events here so that the parent (Tab) does not |
346 // start consuming gestures. | 320 // start consuming gestures. |
347 views::ImageButton::OnGestureEvent(event); | 321 views::ImageButton::OnGestureEvent(event); |
348 event->SetHandled(); | 322 event->SetHandled(); |
349 } | 323 } |
350 | 324 |
| 325 bool NewTabButton::GetHitTestMask(gfx::Path* mask) const { |
| 326 DCHECK(mask); |
| 327 |
| 328 // When the button is sized to the top of the tab strip, we want the hit |
| 329 // test mask to be defined as the complete (rectangular) bounds of the |
| 330 // button. |
| 331 if (tab_strip_->SizeTabButtonToTopOfTabStrip()) { |
| 332 gfx::Rect button_bounds(GetContentsBounds()); |
| 333 button_bounds.set_x(GetMirroredXForRect(button_bounds)); |
| 334 mask->addRect(RectToSkRect(button_bounds)); |
| 335 return true; |
| 336 } |
| 337 |
| 338 SkScalar w = SkIntToScalar(width()); |
| 339 SkScalar v_offset = SkIntToScalar(TabStrip::kNewTabButtonVerticalOffset); |
| 340 |
| 341 // These values are defined by the shape of the new tab image. Should that |
| 342 // image ever change, these values will need to be updated. They're so |
| 343 // custom it's not really worth defining constants for. |
| 344 // These values are correct for regular and USE_ASH versions of the image. |
| 345 mask->moveTo(0, v_offset + 1); |
| 346 mask->lineTo(w - 7, v_offset + 1); |
| 347 mask->lineTo(w - 4, v_offset + 4); |
| 348 mask->lineTo(w, v_offset + 16); |
| 349 mask->lineTo(w - 1, v_offset + 17); |
| 350 mask->lineTo(7, v_offset + 17); |
| 351 mask->lineTo(4, v_offset + 13); |
| 352 mask->lineTo(0, v_offset + 1); |
| 353 mask->close(); |
| 354 |
| 355 return true; |
| 356 } |
| 357 |
351 bool NewTabButton::ShouldWindowContentsBeTransparent() const { | 358 bool NewTabButton::ShouldWindowContentsBeTransparent() const { |
352 return GetWidget() && | 359 return GetWidget() && |
353 GetWidget()->GetTopLevelWidget()->ShouldWindowContentsBeTransparent(); | 360 GetWidget()->GetTopLevelWidget()->ShouldWindowContentsBeTransparent(); |
354 } | 361 } |
355 | 362 |
356 gfx::ImageSkia NewTabButton::GetBackgroundImage( | 363 gfx::ImageSkia NewTabButton::GetBackgroundImage( |
357 views::CustomButton::ButtonState state, | 364 views::CustomButton::ButtonState state, |
358 float scale) const { | 365 float scale) const { |
359 int background_id = 0; | 366 int background_id = 0; |
360 if (ShouldWindowContentsBeTransparent()) { | 367 if (ShouldWindowContentsBeTransparent()) { |
(...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1463 kNewTabButtonAssetWidth, | 1470 kNewTabButtonAssetWidth, |
1464 kNewTabButtonAssetHeight + | 1471 kNewTabButtonAssetHeight + |
1465 kNewTabButtonVerticalOffset); | 1472 kNewTabButtonVerticalOffset); |
1466 newtab_button_ = new NewTabButton(this, this); | 1473 newtab_button_ = new NewTabButton(this, this); |
1467 newtab_button_->SetTooltipText( | 1474 newtab_button_->SetTooltipText( |
1468 l10n_util::GetStringUTF16(IDS_TOOLTIP_NEW_TAB)); | 1475 l10n_util::GetStringUTF16(IDS_TOOLTIP_NEW_TAB)); |
1469 newtab_button_->SetAccessibleName( | 1476 newtab_button_->SetAccessibleName( |
1470 l10n_util::GetStringUTF16(IDS_ACCNAME_NEWTAB)); | 1477 l10n_util::GetStringUTF16(IDS_ACCNAME_NEWTAB)); |
1471 newtab_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, | 1478 newtab_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT, |
1472 views::ImageButton::ALIGN_BOTTOM); | 1479 views::ImageButton::ALIGN_BOTTOM); |
| 1480 newtab_button_->SetEventTargeter( |
| 1481 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(newtab_button_))); |
1473 AddChildView(newtab_button_); | 1482 AddChildView(newtab_button_); |
| 1483 |
1474 if (drop_indicator_width == 0) { | 1484 if (drop_indicator_width == 0) { |
1475 // Direction doesn't matter, both images are the same size. | 1485 // Direction doesn't matter, both images are the same size. |
1476 gfx::ImageSkia* drop_image = GetDropArrowImage(true); | 1486 gfx::ImageSkia* drop_image = GetDropArrowImage(true); |
1477 drop_indicator_width = drop_image->width(); | 1487 drop_indicator_width = drop_image->width(); |
1478 drop_indicator_height = drop_image->height(); | 1488 drop_indicator_height = drop_image->height(); |
1479 } | 1489 } |
1480 } | 1490 } |
1481 | 1491 |
1482 Tab* TabStrip::CreateTab() { | 1492 Tab* TabStrip::CreateTab() { |
1483 Tab* tab = new Tab(this); | 1493 Tab* tab = new Tab(this); |
(...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2687 action = TouchUMA::GESTURE_TABSWITCH_TAP; | 2697 action = TouchUMA::GESTURE_TABSWITCH_TAP; |
2688 TouchUMA::RecordGestureAction(action); | 2698 TouchUMA::RecordGestureAction(action); |
2689 break; | 2699 break; |
2690 } | 2700 } |
2691 | 2701 |
2692 default: | 2702 default: |
2693 break; | 2703 break; |
2694 } | 2704 } |
2695 event->SetHandled(); | 2705 event->SetHandled(); |
2696 } | 2706 } |
OLD | NEW |