| 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/location_bar/open_pdf_in_reader_view.h" | 5 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/views/open_pdf_in_reader_bubble_view.h" | 7 #include "chrome/browser/ui/views/open_pdf_in_reader_bubble_view.h" |
| 8 #include "chrome/grit/generated_resources.h" | 8 #include "chrome/grit/generated_resources.h" |
| 9 #include "chrome/grit/theme_resources.h" | |
| 10 #include "components/pdf/browser/open_pdf_in_reader_prompt_client.h" | 9 #include "components/pdf/browser/open_pdf_in_reader_prompt_client.h" |
| 11 #include "components/pdf/browser/pdf_web_contents_helper.h" | 10 #include "components/pdf/browser/pdf_web_contents_helper.h" |
| 12 #include "ui/accessibility/ax_view_state.h" | 11 #include "ui/accessibility/ax_view_state.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/material_design/material_design_controller.h" | |
| 15 #include "ui/base/resource/resource_bundle.h" | |
| 16 #include "ui/gfx/color_utils.h" | 13 #include "ui/gfx/color_utils.h" |
| 17 #include "ui/gfx/paint_vector_icon.h" | 14 #include "ui/gfx/paint_vector_icon.h" |
| 18 #include "ui/gfx/vector_icons_public.h" | 15 #include "ui/gfx/vector_icons_public.h" |
| 19 #include "ui/native_theme/native_theme.h" | 16 #include "ui/native_theme/native_theme.h" |
| 20 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
| 21 | 18 |
| 22 OpenPDFInReaderView::OpenPDFInReaderView() : bubble_(NULL), model_(NULL) { | 19 OpenPDFInReaderView::OpenPDFInReaderView() : bubble_(nullptr), model_(nullptr) { |
| 23 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 20 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
| 24 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 25 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 26 IDR_OMNIBOX_PDF_ICON)); | |
| 27 } | |
| 28 SetTooltipText(l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_OPEN_IN_READER_LINK)); | 21 SetTooltipText(l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_OPEN_IN_READER_LINK)); |
| 29 } | 22 } |
| 30 | 23 |
| 31 OpenPDFInReaderView::~OpenPDFInReaderView() { | 24 OpenPDFInReaderView::~OpenPDFInReaderView() { |
| 32 if (bubble_) | 25 if (bubble_) |
| 33 bubble_->GetWidget()->RemoveObserver(this); | 26 bubble_->GetWidget()->RemoveObserver(this); |
| 34 } | 27 } |
| 35 | 28 |
| 36 void OpenPDFInReaderView::Update(content::WebContents* web_contents) { | 29 void OpenPDFInReaderView::Update(content::WebContents* web_contents) { |
| 37 model_ = NULL; | 30 model_ = nullptr; |
| 38 if (web_contents) { | 31 if (web_contents) { |
| 39 pdf::PDFWebContentsHelper* pdf_tab_helper = | 32 pdf::PDFWebContentsHelper* pdf_tab_helper = |
| 40 pdf::PDFWebContentsHelper::FromWebContents(web_contents); | 33 pdf::PDFWebContentsHelper::FromWebContents(web_contents); |
| 41 model_ = pdf_tab_helper->open_in_reader_prompt(); | 34 model_ = pdf_tab_helper->open_in_reader_prompt(); |
| 42 } | 35 } |
| 43 | 36 |
| 44 SetVisible(!!model_); | 37 SetVisible(!!model_); |
| 45 | 38 |
| 46 // Hide the bubble if it is currently shown and the icon is hidden. | 39 // Hide the bubble if it is currently shown and the icon is hidden. |
| 47 if (!model_ && bubble_) | 40 if (!model_ && bubble_) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 event.key_code() != ui::VKEY_RETURN) { | 73 event.key_code() != ui::VKEY_RETURN) { |
| 81 return false; | 74 return false; |
| 82 } | 75 } |
| 83 | 76 |
| 84 ShowBubble(); | 77 ShowBubble(); |
| 85 return true; | 78 return true; |
| 86 } | 79 } |
| 87 | 80 |
| 88 void OpenPDFInReaderView::OnNativeThemeChanged( | 81 void OpenPDFInReaderView::OnNativeThemeChanged( |
| 89 const ui::NativeTheme* native_theme) { | 82 const ui::NativeTheme* native_theme) { |
| 90 if (ui::MaterialDesignController::IsModeMaterial()) { | 83 SetImage(gfx::CreateVectorIcon( |
| 91 SetImage(gfx::CreateVectorIcon( | 84 gfx::VectorIconId::PDF, |
| 92 gfx::VectorIconId::PDF, | 85 color_utils::DeriveDefaultIconColor(native_theme->GetSystemColor( |
| 93 color_utils::DeriveDefaultIconColor(native_theme->GetSystemColor( | 86 ui::NativeTheme::kColorId_TextfieldDefaultColor)))); |
| 94 ui::NativeTheme::kColorId_TextfieldDefaultColor)))); | |
| 95 } | |
| 96 } | 87 } |
| 97 | 88 |
| 98 void OpenPDFInReaderView::OnWidgetDestroying(views::Widget* widget) { | 89 void OpenPDFInReaderView::OnWidgetDestroying(views::Widget* widget) { |
| 99 if (!bubble_) | 90 if (!bubble_) |
| 100 return; | 91 return; |
| 101 | 92 |
| 102 bubble_->GetWidget()->RemoveObserver(this); | 93 bubble_->GetWidget()->RemoveObserver(this); |
| 103 bubble_ = NULL; | 94 bubble_ = nullptr; |
| 104 } | 95 } |
| OLD | NEW |