| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" | |
| 6 | |
| 7 #include "chrome/browser/ui/views/open_pdf_in_reader_bubble_view.h" | |
| 8 #include "chrome/grit/generated_resources.h" | |
| 9 #include "components/pdf/browser/open_pdf_in_reader_prompt_client.h" | |
| 10 #include "components/pdf/browser/pdf_web_contents_helper.h" | |
| 11 #include "ui/accessibility/ax_node_data.h" | |
| 12 #include "ui/base/l10n/l10n_util.h" | |
| 13 #include "ui/gfx/color_utils.h" | |
| 14 #include "ui/gfx/paint_vector_icon.h" | |
| 15 #include "ui/gfx/vector_icons_public.h" | |
| 16 #include "ui/native_theme/native_theme.h" | |
| 17 #include "ui/views/widget/widget.h" | |
| 18 | |
| 19 OpenPDFInReaderView::OpenPDFInReaderView() : bubble_(nullptr), model_(nullptr) { | |
| 20 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | |
| 21 SetTooltipText(l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_OPEN_IN_READER_LINK)); | |
| 22 } | |
| 23 | |
| 24 OpenPDFInReaderView::~OpenPDFInReaderView() { | |
| 25 if (bubble_) | |
| 26 bubble_->GetWidget()->RemoveObserver(this); | |
| 27 } | |
| 28 | |
| 29 void OpenPDFInReaderView::Update(content::WebContents* web_contents) { | |
| 30 model_ = nullptr; | |
| 31 if (web_contents) { | |
| 32 pdf::PDFWebContentsHelper* pdf_tab_helper = | |
| 33 pdf::PDFWebContentsHelper::FromWebContents(web_contents); | |
| 34 model_ = pdf_tab_helper->open_in_reader_prompt(); | |
| 35 } | |
| 36 | |
| 37 SetVisible(!!model_); | |
| 38 | |
| 39 // Hide the bubble if it is currently shown and the icon is hidden. | |
| 40 if (!model_ && bubble_) | |
| 41 bubble_->GetWidget()->Hide(); | |
| 42 } | |
| 43 | |
| 44 void OpenPDFInReaderView::ShowBubble() { | |
| 45 if (bubble_) | |
| 46 return; | |
| 47 | |
| 48 DCHECK(model_); | |
| 49 bubble_ = new OpenPDFInReaderBubbleView(this, model_); | |
| 50 views::BubbleDialogDelegateView::CreateBubble(bubble_); | |
| 51 bubble_->GetWidget()->AddObserver(this); | |
| 52 bubble_->GetWidget()->Show(); | |
| 53 } | |
| 54 | |
| 55 void OpenPDFInReaderView::GetAccessibleNodeData(ui::AXNodeData* node_data) { | |
| 56 ImageView::GetAccessibleNodeData(node_data); | |
| 57 node_data->SetName(l10n_util::GetStringUTF8(IDS_ACCNAME_OPEN_PDF_IN_READER)); | |
| 58 node_data->role = ui::AX_ROLE_BUTTON; | |
| 59 } | |
| 60 | |
| 61 bool OpenPDFInReaderView::OnMousePressed(const ui::MouseEvent& event) { | |
| 62 // Show the bubble on mouse release; that is standard button behavior. | |
| 63 return true; | |
| 64 } | |
| 65 | |
| 66 void OpenPDFInReaderView::OnMouseReleased(const ui::MouseEvent& event) { | |
| 67 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) | |
| 68 ShowBubble(); | |
| 69 } | |
| 70 | |
| 71 bool OpenPDFInReaderView::OnKeyPressed(const ui::KeyEvent& event) { | |
| 72 if (event.key_code() != ui::VKEY_SPACE && | |
| 73 event.key_code() != ui::VKEY_RETURN) { | |
| 74 return false; | |
| 75 } | |
| 76 | |
| 77 ShowBubble(); | |
| 78 return true; | |
| 79 } | |
| 80 | |
| 81 void OpenPDFInReaderView::OnNativeThemeChanged( | |
| 82 const ui::NativeTheme* native_theme) { | |
| 83 SetImage(gfx::CreateVectorIcon( | |
| 84 gfx::VectorIconId::PDF, | |
| 85 color_utils::DeriveDefaultIconColor(native_theme->GetSystemColor( | |
| 86 ui::NativeTheme::kColorId_TextfieldDefaultColor)))); | |
| 87 } | |
| 88 | |
| 89 void OpenPDFInReaderView::OnWidgetDestroying(views::Widget* widget) { | |
| 90 if (!bubble_) | |
| 91 return; | |
| 92 | |
| 93 bubble_->GetWidget()->RemoveObserver(this); | |
| 94 bubble_ = nullptr; | |
| 95 } | |
| OLD | NEW |