| 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 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "chrome/browser/ui/views/tabs/touch_tab_strip_layout.h" | 25 #include "chrome/browser/ui/views/tabs/touch_tab_strip_layout.h" |
| 26 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
| 27 #include "grit/theme_resources.h" | 27 #include "grit/theme_resources.h" |
| 28 #include "grit/theme_resources_standard.h" | 28 #include "grit/theme_resources_standard.h" |
| 29 #include "ui/base/accessibility/accessible_view_state.h" | 29 #include "ui/base/accessibility/accessible_view_state.h" |
| 30 #include "ui/base/animation/animation_container.h" | 30 #include "ui/base/animation/animation_container.h" |
| 31 #include "ui/base/animation/throb_animation.h" | 31 #include "ui/base/animation/throb_animation.h" |
| 32 #include "ui/base/dragdrop/drag_drop_types.h" | 32 #include "ui/base/dragdrop/drag_drop_types.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "ui/base/layout.h" | 34 #include "ui/base/layout.h" |
| 35 #include "ui/base/layout.h" |
| 35 #include "ui/base/resource/resource_bundle.h" | 36 #include "ui/base/resource/resource_bundle.h" |
| 36 #include "ui/gfx/canvas.h" | 37 #include "ui/gfx/canvas.h" |
| 37 #include "ui/gfx/path.h" | 38 #include "ui/gfx/path.h" |
| 38 #include "ui/gfx/screen.h" | 39 #include "ui/gfx/screen.h" |
| 39 #include "ui/gfx/size.h" | 40 #include "ui/gfx/size.h" |
| 40 #include "ui/gfx/skbitmap_operations.h" | 41 #include "ui/gfx/skbitmap_operations.h" |
| 41 #include "ui/base/layout.h" | |
| 42 #include "ui/views/controls/image_view.h" | 42 #include "ui/views/controls/image_view.h" |
| 43 #include "ui/views/mouse_watcher_view_host.h" | 43 #include "ui/views/mouse_watcher_view_host.h" |
| 44 #include "ui/views/view_model_utils.h" | 44 #include "ui/views/view_model_utils.h" |
| 45 #include "ui/views/widget/default_theme_provider.h" | 45 #include "ui/views/widget/default_theme_provider.h" |
| 46 #include "ui/views/widget/root_view.h" | 46 #include "ui/views/widget/root_view.h" |
| 47 #include "ui/views/widget/widget.h" | 47 #include "ui/views/widget/widget.h" |
| 48 #include "ui/views/window/non_client_view.h" | 48 #include "ui/views/window/non_client_view.h" |
| 49 | 49 |
| 50 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
| 51 #include "base/win/metro.h" | 51 #include "base/win/metro.h" |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 // be able to click on complete bounds, and so don't return a custom hit | 317 // be able to click on complete bounds, and so don't return a custom hit |
| 318 // mask. | 318 // mask. |
| 319 return !tab_strip_->SizeTabButtonToTopOfTabStrip(); | 319 return !tab_strip_->SizeTabButtonToTopOfTabStrip(); |
| 320 } | 320 } |
| 321 | 321 |
| 322 void NewTabButton::GetHitTestMask(gfx::Path* path) const { | 322 void NewTabButton::GetHitTestMask(gfx::Path* path) const { |
| 323 DCHECK(path); | 323 DCHECK(path); |
| 324 | 324 |
| 325 SkScalar w = SkIntToScalar(width()); | 325 SkScalar w = SkIntToScalar(width()); |
| 326 | 326 |
| 327 // These values are defined by the shape of the new tab bitmap. Should that | 327 // These values are defined by the shape of the new tab image. Should that |
| 328 // bitmap ever change, these values will need to be updated. They're so | 328 // image ever change, these values will need to be updated. They're so |
| 329 // custom it's not really worth defining constants for. | 329 // custom it's not really worth defining constants for. |
| 330 // These values are correct for regular and USE_ASH versions of the bitmap. | 330 // These values are correct for regular and USE_ASH versions of the image. |
| 331 path->moveTo(0, 1); | 331 path->moveTo(0, 1); |
| 332 path->lineTo(w - 7, 1); | 332 path->lineTo(w - 7, 1); |
| 333 path->lineTo(w - 4, 4); | 333 path->lineTo(w - 4, 4); |
| 334 path->lineTo(w, 16); | 334 path->lineTo(w, 16); |
| 335 path->lineTo(w - 1, 17); | 335 path->lineTo(w - 1, 17); |
| 336 path->lineTo(7, 17); | 336 path->lineTo(7, 17); |
| 337 path->lineTo(4, 13); | 337 path->lineTo(4, 13); |
| 338 path->lineTo(0, 1); | 338 path->lineTo(0, 1); |
| 339 path->close(); | 339 path->close(); |
| 340 } | 340 } |
| 341 | 341 |
| 342 #if defined(OS_WIN) && !defined(USE_AURA) | 342 #if defined(OS_WIN) && !defined(USE_AURA) |
| 343 void NewTabButton::OnMouseReleased(const views::MouseEvent& event) { | 343 void NewTabButton::OnMouseReleased(const views::MouseEvent& event) { |
| 344 if (event.IsOnlyRightMouseButton()) { | 344 if (event.IsOnlyRightMouseButton()) { |
| 345 gfx::Point point(event.x(), event.y()); | 345 gfx::Point point(event.x(), event.y()); |
| 346 views::View::ConvertPointToScreen(this, &point); | 346 views::View::ConvertPointToScreen(this, &point); |
| 347 ui::ShowSystemMenu(GetWidget()->GetNativeView(), point.x(), point.y()); | 347 ui::ShowSystemMenu(GetWidget()->GetNativeView(), point.x(), point.y()); |
| 348 SetState(BS_NORMAL); | 348 SetState(BS_NORMAL); |
| 349 return; | 349 return; |
| 350 } | 350 } |
| 351 views::ImageButton::OnMouseReleased(event); | 351 views::ImageButton::OnMouseReleased(event); |
| 352 } | 352 } |
| 353 #endif | 353 #endif |
| 354 | 354 |
| 355 void NewTabButton::OnPaint(gfx::Canvas* canvas) { | 355 void NewTabButton::OnPaint(gfx::Canvas* canvas) { |
| 356 SkBitmap bitmap = GetBitmap(); | 356 SkBitmap image = GetBitmap(); |
| 357 canvas->DrawBitmapInt(bitmap, 0, height() - bitmap.height()); | 357 canvas->DrawBitmapInt(image, 0, height() - image.height()); |
| 358 } | 358 } |
| 359 | 359 |
| 360 bool NewTabButton::ShouldUseNativeFrame() const { | 360 bool NewTabButton::ShouldUseNativeFrame() const { |
| 361 return GetWidget() && | 361 return GetWidget() && |
| 362 GetWidget()->GetTopLevelWidget()->ShouldUseNativeFrame(); | 362 GetWidget()->GetTopLevelWidget()->ShouldUseNativeFrame(); |
| 363 } | 363 } |
| 364 | 364 |
| 365 SkBitmap NewTabButton::GetBackgroundBitmap( | 365 SkBitmap NewTabButton::GetBackgroundBitmap( |
| 366 views::CustomButton::ButtonState state) const { | 366 views::CustomButton::ButtonState state) const { |
| 367 int background_id = 0; | 367 int background_id = 0; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 379 alpha = ShouldUseNativeFrame() ? kNativeFrameInactiveTabAlpha : 255; | 379 alpha = ShouldUseNativeFrame() ? kNativeFrameInactiveTabAlpha : 255; |
| 380 break; | 380 break; |
| 381 case views::CustomButton::BS_PUSHED: | 381 case views::CustomButton::BS_PUSHED: |
| 382 alpha = 145; | 382 alpha = 145; |
| 383 break; | 383 break; |
| 384 default: | 384 default: |
| 385 NOTREACHED(); | 385 NOTREACHED(); |
| 386 break; | 386 break; |
| 387 } | 387 } |
| 388 | 388 |
| 389 SkBitmap* mask = GetThemeProvider()->GetBitmapNamed(IDR_NEWTAB_BUTTON_MASK); | 389 gfx::ImageSkia* mask = |
| 390 GetThemeProvider()->GetImageSkiaNamed(IDR_NEWTAB_BUTTON_MASK); |
| 390 int height = mask->height(); | 391 int height = mask->height(); |
| 391 int width = mask->width(); | 392 int width = mask->width(); |
| 392 gfx::Canvas canvas(gfx::Size(width, height), false); | 393 gfx::Canvas canvas(gfx::Size(width, height), false); |
| 393 | 394 |
| 394 // For custom images the background starts at the top of the tab strip. | 395 // For custom images the background starts at the top of the tab strip. |
| 395 // Otherwise the background starts at the top of the frame. | 396 // Otherwise the background starts at the top of the frame. |
| 396 SkBitmap* background = GetThemeProvider()->GetBitmapNamed(background_id); | 397 gfx::ImageSkia* background = |
| 398 GetThemeProvider()->GetImageSkiaNamed(background_id); |
| 397 int offset_y = GetThemeProvider()->HasCustomImage(background_id) ? | 399 int offset_y = GetThemeProvider()->HasCustomImage(background_id) ? |
| 398 0 : background_offset_.y(); | 400 0 : background_offset_.y(); |
| 399 canvas.TileImageInt(*background, GetMirroredX() + background_offset_.x(), | 401 canvas.TileImageInt(*background, GetMirroredX() + background_offset_.x(), |
| 400 newtab_button_v_offset() + offset_y, 0, 0, width, height); | 402 newtab_button_v_offset() + offset_y, 0, 0, width, height); |
| 401 | 403 |
| 402 if (alpha != 255) { | 404 if (alpha != 255) { |
| 403 SkPaint paint; | 405 SkPaint paint; |
| 404 paint.setColor(SkColorSetARGB(alpha, 255, 255, 255)); | 406 paint.setColor(SkColorSetARGB(alpha, 255, 255, 255)); |
| 405 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); | 407 paint.setXfermodeMode(SkXfermode::kDstIn_Mode); |
| 406 paint.setStyle(SkPaint::kFill_Style); | 408 paint.setStyle(SkPaint::kFill_Style); |
| 407 canvas.DrawRect(gfx::Rect(0, 0, width, height), paint); | 409 canvas.DrawRect(gfx::Rect(0, 0, width, height), paint); |
| 408 } | 410 } |
| 409 | 411 |
| 410 // White highlight on hover. | 412 // White highlight on hover. |
| 411 if (state == views::CustomButton::BS_HOT) | 413 if (state == views::CustomButton::BS_HOT) |
| 412 canvas.FillRect(gfx::Rect(size()), SkColorSetARGB(64, 255, 255, 255)); | 414 canvas.FillRect(gfx::Rect(size()), SkColorSetARGB(64, 255, 255, 255)); |
| 413 | 415 |
| 414 return SkBitmapOperations::CreateMaskedBitmap(canvas.ExtractBitmap(), *mask); | 416 return SkBitmapOperations::CreateMaskedBitmap(canvas.ExtractBitmap(), *mask); |
| 415 } | 417 } |
| 416 | 418 |
| 417 SkBitmap NewTabButton::GetBitmapForState( | 419 SkBitmap NewTabButton::GetBitmapForState( |
| 418 views::CustomButton::ButtonState state) const { | 420 views::CustomButton::ButtonState state) const { |
| 419 int overlay_id = state == views::CustomButton::BS_PUSHED ? | 421 int overlay_id = state == views::CustomButton::BS_PUSHED ? |
| 420 IDR_NEWTAB_BUTTON_P : IDR_NEWTAB_BUTTON; | 422 IDR_NEWTAB_BUTTON_P : IDR_NEWTAB_BUTTON; |
| 421 SkBitmap* overlay = GetThemeProvider()->GetBitmapNamed(overlay_id); | 423 gfx::ImageSkia* overlay = GetThemeProvider()->GetImageSkiaNamed(overlay_id); |
| 422 | 424 |
| 423 gfx::Canvas canvas(gfx::Size(overlay->width(), overlay->height()), false); | 425 gfx::Canvas canvas(gfx::Size(overlay->width(), overlay->height()), false); |
| 424 canvas.DrawBitmapInt(GetBackgroundBitmap(state), 0, 0); | 426 canvas.DrawBitmapInt(GetBackgroundBitmap(state), 0, 0); |
| 425 | 427 |
| 426 // Draw the button border with a slight alpha. | 428 // Draw the button border with a slight alpha. |
| 427 const int kNativeFrameOverlayAlpha = 178; | 429 const int kNativeFrameOverlayAlpha = 178; |
| 428 const int kOpaqueFrameOverlayAlpha = 230; | 430 const int kOpaqueFrameOverlayAlpha = 230; |
| 429 canvas.SaveLayerAlpha(ShouldUseNativeFrame() ? | 431 canvas.SaveLayerAlpha(ShouldUseNativeFrame() ? |
| 430 kNativeFrameOverlayAlpha : kOpaqueFrameOverlayAlpha); | 432 kNativeFrameOverlayAlpha : kOpaqueFrameOverlayAlpha); |
| 431 canvas.DrawBitmapInt(*overlay, 0, 0); | 433 canvas.DrawBitmapInt(*overlay, 0, 0); |
| (...skipping 1826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2258 | 2260 |
| 2259 int mini_tab_count = GetMiniTabCount(); | 2261 int mini_tab_count = GetMiniTabCount(); |
| 2260 int normal_count = tab_count() - mini_tab_count; | 2262 int normal_count = tab_count() - mini_tab_count; |
| 2261 if (normal_count == 0 || normal_count == mini_tab_count) | 2263 if (normal_count == 0 || normal_count == mini_tab_count) |
| 2262 return false; | 2264 return false; |
| 2263 int x = GetStartXForNormalTabs(); | 2265 int x = GetStartXForNormalTabs(); |
| 2264 int available_width = width() - x - new_tab_button_width(); | 2266 int available_width = width() - x - new_tab_button_width(); |
| 2265 return (Tab::GetTouchWidth() * normal_count + | 2267 return (Tab::GetTouchWidth() * normal_count + |
| 2266 tab_h_offset() * (normal_count - 1)) > available_width; | 2268 tab_h_offset() * (normal_count - 1)) > available_width; |
| 2267 } | 2269 } |
| OLD | NEW |