| 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/content_settings/content_setting_image_model.h" | 5 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "ui/gfx/color_palette.h" | 21 #include "ui/gfx/color_palette.h" |
| 22 #include "ui/gfx/color_utils.h" | 22 #include "ui/gfx/color_utils.h" |
| 23 #include "ui/gfx/paint_vector_icon.h" | 23 #include "ui/gfx/paint_vector_icon.h" |
| 24 #include "ui/gfx/vector_icons_public.h" | 24 #include "ui/gfx/vector_icons_public.h" |
| 25 | 25 |
| 26 using content::WebContents; | 26 using content::WebContents; |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 bool UseVectorGraphics() { | 30 bool UseVectorGraphics() { |
| 31 #if defined(OS_MACOSX) | |
| 32 return false; | |
| 33 #else | |
| 34 return ui::MaterialDesignController::IsModeMaterial(); | 31 return ui::MaterialDesignController::IsModeMaterial(); |
| 35 #endif | |
| 36 } | 32 } |
| 37 | 33 |
| 38 } // namespace | 34 } // namespace |
| 39 | 35 |
| 40 // The image models hierarchy: | 36 // The image models hierarchy: |
| 41 // | 37 // |
| 42 // ContentSettingImageModel - base class | 38 // ContentSettingImageModel - base class |
| 43 // ContentSettingSimpleImageModel - single content setting | 39 // ContentSettingSimpleImageModel - single content setting |
| 44 // ContentSettingBlockedImageModel - generic blocked setting | 40 // ContentSettingBlockedImageModel - generic blocked setting |
| 45 // ContentSettingGeolocationImageModel - geolocation | 41 // ContentSettingGeolocationImageModel - geolocation |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 : gfx::VectorIconId::BLOCKED_BADGE); | 514 : gfx::VectorIconId::BLOCKED_BADGE); |
| 519 } | 515 } |
| 520 set_tooltip(l10n_util::GetStringUTF16(allowed | 516 set_tooltip(l10n_util::GetStringUTF16(allowed |
| 521 ? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP | 517 ? IDS_MIDI_SYSEX_ALLOWED_TOOLTIP |
| 522 : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); | 518 : IDS_MIDI_SYSEX_BLOCKED_TOOLTIP)); |
| 523 } | 519 } |
| 524 | 520 |
| 525 // Base class ------------------------------------------------------------------ | 521 // Base class ------------------------------------------------------------------ |
| 526 | 522 |
| 527 gfx::Image ContentSettingImageModel::GetIcon(SkColor nearby_text_color) const { | 523 gfx::Image ContentSettingImageModel::GetIcon(SkColor nearby_text_color) const { |
| 524 SkColor icon_color = nearby_text_color; |
| 525 #if !defined(OS_MACOSX) |
| 526 icon_color = color_utils::DeriveDefaultIconColor(nearby_text_color); |
| 527 #endif |
| 528 |
| 528 return UseVectorGraphics() | 529 return UseVectorGraphics() |
| 529 ? gfx::Image(gfx::CreateVectorIconWithBadge( | 530 ? gfx::Image(gfx::CreateVectorIconWithBadge( |
| 530 vector_icon_id_, 16, | 531 vector_icon_id_, 16, icon_color, vector_icon_badge_id_)) |
| 531 color_utils::DeriveDefaultIconColor(nearby_text_color), | |
| 532 vector_icon_badge_id_)) | |
| 533 : raster_icon_; | 532 : raster_icon_; |
| 534 } | 533 } |
| 535 | 534 |
| 536 ContentSettingImageModel::ContentSettingImageModel() | 535 ContentSettingImageModel::ContentSettingImageModel() |
| 537 : is_visible_(false), | 536 : is_visible_(false), |
| 538 raster_icon_id_(0), | 537 raster_icon_id_(0), |
| 539 vector_icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE), | 538 vector_icon_id_(gfx::VectorIconId::VECTOR_ICON_NONE), |
| 540 vector_icon_badge_id_(gfx::VectorIconId::VECTOR_ICON_NONE), | 539 vector_icon_badge_id_(gfx::VectorIconId::VECTOR_ICON_NONE), |
| 541 explanatory_string_id_(0) {} | 540 explanatory_string_id_(0) {} |
| 542 | 541 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 570 result.push_back(new ContentSettingMIDISysExImageModel()); | 569 result.push_back(new ContentSettingMIDISysExImageModel()); |
| 571 | 570 |
| 572 return result; | 571 return result; |
| 573 } | 572 } |
| 574 | 573 |
| 575 void ContentSettingImageModel::SetIconByResourceId(int id) { | 574 void ContentSettingImageModel::SetIconByResourceId(int id) { |
| 576 raster_icon_id_ = id; | 575 raster_icon_id_ = id; |
| 577 raster_icon_ = | 576 raster_icon_ = |
| 578 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(id); | 577 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(id); |
| 579 } | 578 } |
| 579 |
| 580 #if defined(OS_MACOSX) |
| 581 bool ContentSettingImageModel::UpdateFromWebContentsAndCheckIfIconChanged( |
| 582 content::WebContents* web_contents) { |
| 583 if (UseVectorGraphics()) { |
| 584 gfx::VectorIconId old_vector_icon = vector_icon_id_; |
| 585 gfx::VectorIconId old_badge_icon = vector_icon_badge_id_; |
| 586 UpdateFromWebContents(web_contents); |
| 587 return old_vector_icon != vector_icon_id_ && |
| 588 old_badge_icon != vector_icon_badge_id_; |
| 589 } else { |
| 590 int old_icon = raster_icon_id_; |
| 591 UpdateFromWebContents(web_contents); |
| 592 return old_icon != raster_icon_id_; |
| 593 } |
| 594 } |
| 595 #endif |
| OLD | NEW |