Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(574)

Side by Side Diff: chrome/browser/ui/views/tabs/tab_strip.cc

Issue 283383005: Initial sets of fixes for themes to work well with HiDPI Windows. More changes coming in a separate… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/base/resource/resource_bundle.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; 220 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
221 #endif 221 #endif
222 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 222 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
223 223
224 // Overridden from ui::EventHandler: 224 // Overridden from ui::EventHandler:
225 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 225 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
226 226
227 private: 227 private:
228 bool ShouldWindowContentsBeTransparent() const; 228 bool ShouldWindowContentsBeTransparent() const;
229 gfx::ImageSkia GetBackgroundImage(views::CustomButton::ButtonState state, 229 gfx::ImageSkia GetBackgroundImage(views::CustomButton::ButtonState state,
230 ui::ScaleFactor scale_factor) const; 230 float scale) const;
231 gfx::ImageSkia GetImageForState(views::CustomButton::ButtonState state, 231 gfx::ImageSkia GetImageForState(views::CustomButton::ButtonState state,
232 ui::ScaleFactor scale_factor) const; 232 float scale) const;
233 gfx::ImageSkia GetImageForScale(ui::ScaleFactor scale_factor) const; 233 gfx::ImageSkia GetImageForScale(float scale) const;
234 234
235 // Tab strip that contains this button. 235 // Tab strip that contains this button.
236 TabStrip* tab_strip_; 236 TabStrip* tab_strip_;
237 237
238 // The offset used to paint the background image. 238 // The offset used to paint the background image.
239 gfx::Point background_offset_; 239 gfx::Point background_offset_;
240 240
241 // were we destroyed? 241 // were we destroyed?
242 bool* destroyed_; 242 bool* destroyed_;
243 243
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 300
301 destroyed_ = NULL; 301 destroyed_ = NULL;
302 SetState(views::CustomButton::STATE_NORMAL); 302 SetState(views::CustomButton::STATE_NORMAL);
303 return; 303 return;
304 } 304 }
305 views::ImageButton::OnMouseReleased(event); 305 views::ImageButton::OnMouseReleased(event);
306 } 306 }
307 #endif 307 #endif
308 308
309 void NewTabButton::OnPaint(gfx::Canvas* canvas) { 309 void NewTabButton::OnPaint(gfx::Canvas* canvas) {
310 gfx::ImageSkia image = 310 gfx::ImageSkia image = GetImageForScale(canvas->image_scale());
311 GetImageForScale(ui::GetSupportedScaleFactor(canvas->image_scale()));
312 canvas->DrawImageInt(image, 0, height() - image.height()); 311 canvas->DrawImageInt(image, 0, height() - image.height());
313 } 312 }
314 313
315 void NewTabButton::OnGestureEvent(ui::GestureEvent* event) { 314 void NewTabButton::OnGestureEvent(ui::GestureEvent* event) {
316 // Consume all gesture events here so that the parent (Tab) does not 315 // Consume all gesture events here so that the parent (Tab) does not
317 // start consuming gestures. 316 // start consuming gestures.
318 views::ImageButton::OnGestureEvent(event); 317 views::ImageButton::OnGestureEvent(event);
319 event->SetHandled(); 318 event->SetHandled();
320 } 319 }
321 320
322 bool NewTabButton::ShouldWindowContentsBeTransparent() const { 321 bool NewTabButton::ShouldWindowContentsBeTransparent() const {
323 return GetWidget() && 322 return GetWidget() &&
324 GetWidget()->GetTopLevelWidget()->ShouldWindowContentsBeTransparent(); 323 GetWidget()->GetTopLevelWidget()->ShouldWindowContentsBeTransparent();
325 } 324 }
326 325
327 gfx::ImageSkia NewTabButton::GetBackgroundImage( 326 gfx::ImageSkia NewTabButton::GetBackgroundImage(
328 views::CustomButton::ButtonState state, 327 views::CustomButton::ButtonState state,
329 ui::ScaleFactor scale_factor) const { 328 float scale) const {
330 int background_id = 0; 329 int background_id = 0;
331 if (ShouldWindowContentsBeTransparent()) { 330 if (ShouldWindowContentsBeTransparent()) {
332 background_id = IDR_THEME_TAB_BACKGROUND_V; 331 background_id = IDR_THEME_TAB_BACKGROUND_V;
333 } else if (tab_strip_->controller()->IsIncognito()) { 332 } else if (tab_strip_->controller()->IsIncognito()) {
334 background_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO; 333 background_id = IDR_THEME_TAB_BACKGROUND_INCOGNITO;
335 } else { 334 } else {
336 background_id = IDR_THEME_TAB_BACKGROUND; 335 background_id = IDR_THEME_TAB_BACKGROUND;
337 } 336 }
338 337
339 int alpha = 0; 338 int alpha = 0;
340 switch (state) { 339 switch (state) {
341 case views::CustomButton::STATE_NORMAL: 340 case views::CustomButton::STATE_NORMAL:
342 case views::CustomButton::STATE_HOVERED: 341 case views::CustomButton::STATE_HOVERED:
343 alpha = ShouldWindowContentsBeTransparent() ? kGlassFrameInactiveTabAlpha 342 alpha = ShouldWindowContentsBeTransparent() ? kGlassFrameInactiveTabAlpha
344 : 255; 343 : 255;
345 break; 344 break;
346 case views::CustomButton::STATE_PRESSED: 345 case views::CustomButton::STATE_PRESSED:
347 alpha = 145; 346 alpha = 145;
348 break; 347 break;
349 default: 348 default:
350 NOTREACHED(); 349 NOTREACHED();
351 break; 350 break;
352 } 351 }
353 352
354 gfx::ImageSkia* mask = 353 gfx::ImageSkia* mask =
355 GetThemeProvider()->GetImageSkiaNamed(IDR_NEWTAB_BUTTON_MASK); 354 GetThemeProvider()->GetImageSkiaNamed(IDR_NEWTAB_BUTTON_MASK);
356 int height = mask->height(); 355 int height = mask->height();
357 int width = mask->width(); 356 int width = mask->width();
358 float scale = ui::GetImageScale(scale_factor);
359 // The canvas and mask has to use the same scale factor. 357 // The canvas and mask has to use the same scale factor.
360 if (!mask->HasRepresentation(scale)) 358 if (!mask->HasRepresentation(scale))
361 scale_factor = ui::SCALE_FACTOR_100P; 359 scale = ui::GetScaleForScaleFactor(ui::SCALE_FACTOR_100P);
362 360
363 gfx::Canvas canvas(gfx::Size(width, height), scale, false); 361 gfx::Canvas canvas(gfx::Size(width, height), scale, false);
364 362
365 // For custom images the background starts at the top of the tab strip. 363 // For custom images the background starts at the top of the tab strip.
366 // Otherwise the background starts at the top of the frame. 364 // Otherwise the background starts at the top of the frame.
367 gfx::ImageSkia* background = 365 gfx::ImageSkia* background =
368 GetThemeProvider()->GetImageSkiaNamed(background_id); 366 GetThemeProvider()->GetImageSkiaNamed(background_id);
369 int offset_y = GetThemeProvider()->HasCustomImage(background_id) ? 367 int offset_y = GetThemeProvider()->HasCustomImage(background_id) ?
370 0 : background_offset_.y(); 368 0 : background_offset_.y();
371 369
(...skipping 21 matching lines...) Expand all
393 // White highlight on hover. 391 // White highlight on hover.
394 if (state == views::CustomButton::STATE_HOVERED) 392 if (state == views::CustomButton::STATE_HOVERED)
395 canvas.FillRect(GetLocalBounds(), SkColorSetARGB(64, 255, 255, 255)); 393 canvas.FillRect(GetLocalBounds(), SkColorSetARGB(64, 255, 255, 255));
396 394
397 return gfx::ImageSkiaOperations::CreateMaskedImage( 395 return gfx::ImageSkiaOperations::CreateMaskedImage(
398 gfx::ImageSkia(canvas.ExtractImageRep()), *mask); 396 gfx::ImageSkia(canvas.ExtractImageRep()), *mask);
399 } 397 }
400 398
401 gfx::ImageSkia NewTabButton::GetImageForState( 399 gfx::ImageSkia NewTabButton::GetImageForState(
402 views::CustomButton::ButtonState state, 400 views::CustomButton::ButtonState state,
403 ui::ScaleFactor scale_factor) const { 401 float scale) const {
404 const int overlay_id = state == views::CustomButton::STATE_PRESSED ? 402 const int overlay_id = state == views::CustomButton::STATE_PRESSED ?
405 IDR_NEWTAB_BUTTON_P : IDR_NEWTAB_BUTTON; 403 IDR_NEWTAB_BUTTON_P : IDR_NEWTAB_BUTTON;
406 gfx::ImageSkia* overlay = GetThemeProvider()->GetImageSkiaNamed(overlay_id); 404 gfx::ImageSkia* overlay = GetThemeProvider()->GetImageSkiaNamed(overlay_id);
407 405
408 gfx::Canvas canvas( 406 gfx::Canvas canvas(
409 gfx::Size(overlay->width(), overlay->height()), 407 gfx::Size(overlay->width(), overlay->height()),
410 ui::GetImageScale(scale_factor), 408 scale,
411 false); 409 false);
412 canvas.DrawImageInt(GetBackgroundImage(state, scale_factor), 0, 0); 410 canvas.DrawImageInt(GetBackgroundImage(state, scale), 0, 0);
413 411
414 // Draw the button border with a slight alpha. 412 // Draw the button border with a slight alpha.
415 const int kGlassFrameOverlayAlpha = 178; 413 const int kGlassFrameOverlayAlpha = 178;
416 const int kOpaqueFrameOverlayAlpha = 230; 414 const int kOpaqueFrameOverlayAlpha = 230;
417 uint8 alpha = ShouldWindowContentsBeTransparent() ? 415 uint8 alpha = ShouldWindowContentsBeTransparent() ?
418 kGlassFrameOverlayAlpha : kOpaqueFrameOverlayAlpha; 416 kGlassFrameOverlayAlpha : kOpaqueFrameOverlayAlpha;
419 canvas.DrawImageInt(*overlay, 0, 0, alpha); 417 canvas.DrawImageInt(*overlay, 0, 0, alpha);
420 418
421 return gfx::ImageSkia(canvas.ExtractImageRep()); 419 return gfx::ImageSkia(canvas.ExtractImageRep());
422 } 420 }
423 421
424 gfx::ImageSkia NewTabButton::GetImageForScale( 422 gfx::ImageSkia NewTabButton::GetImageForScale(float scale) const {
425 ui::ScaleFactor scale_factor) const {
426 if (!hover_animation_->is_animating()) 423 if (!hover_animation_->is_animating())
427 return GetImageForState(state(), scale_factor); 424 return GetImageForState(state(), scale);
428 return gfx::ImageSkiaOperations::CreateBlendedImage( 425 return gfx::ImageSkiaOperations::CreateBlendedImage(
429 GetImageForState(views::CustomButton::STATE_NORMAL, scale_factor), 426 GetImageForState(views::CustomButton::STATE_NORMAL, scale),
430 GetImageForState(views::CustomButton::STATE_HOVERED, scale_factor), 427 GetImageForState(views::CustomButton::STATE_HOVERED, scale),
431 hover_animation_->GetCurrentValue()); 428 hover_animation_->GetCurrentValue());
432 } 429 }
433 430
434 /////////////////////////////////////////////////////////////////////////////// 431 ///////////////////////////////////////////////////////////////////////////////
435 // TabStrip::RemoveTabDelegate 432 // TabStrip::RemoveTabDelegate
436 // 433 //
437 // AnimationDelegate used when removing a tab. Does the necessary cleanup when 434 // AnimationDelegate used when removing a tab. Does the necessary cleanup when
438 // done. 435 // done.
439 class TabStrip::RemoveTabDelegate 436 class TabStrip::RemoveTabDelegate
440 : public views::BoundsAnimator::OwnedAnimationDelegate { 437 : public views::BoundsAnimator::OwnedAnimationDelegate {
(...skipping 2204 matching lines...) Expand 10 before | Expand all | Expand 10 after
2645 else 2642 else
2646 RemoveMessageLoopObserver(); 2643 RemoveMessageLoopObserver();
2647 } 2644 }
2648 2645
2649 bool TabStrip::GetAdjustLayout() const { 2646 bool TabStrip::GetAdjustLayout() const {
2650 if (!adjust_layout_) 2647 if (!adjust_layout_)
2651 return false; 2648 return false;
2652 return chrome::GetHostDesktopTypeForNativeView( 2649 return chrome::GetHostDesktopTypeForNativeView(
2653 GetWidget()->GetNativeView()) == chrome::HOST_DESKTOP_TYPE_ASH; 2650 GetWidget()->GetNativeView()) == chrome::HOST_DESKTOP_TYPE_ASH;
2654 } 2651 }
OLDNEW
« no previous file with comments | « no previous file | ui/base/resource/resource_bundle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698