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.
5 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h"
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 "grit/theme_resources.h"
12 #include "ui/accessibility/ax_view_state.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/views/widget/widget.h"
17 OpenPDFInReaderView::OpenPDFInReaderView() : bubble_(NULL
), model_(NULL
) {
18 SetAccessibilityFocusable(true);
19 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
20 IDR_OMNIBOX_PDF_ICON
));
21 SetTooltipText(l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_OPEN_IN_READER_LINK
));
24 OpenPDFInReaderView::~OpenPDFInReaderView() {
26 bubble_
->GetWidget()->RemoveObserver(this);
29 void OpenPDFInReaderView::Update(content::WebContents
* web_contents
) {
32 pdf::PDFWebContentsHelper
* pdf_tab_helper
=
33 pdf::PDFWebContentsHelper::FromWebContents(web_contents
);
34 model_
= pdf_tab_helper
->open_in_reader_prompt();
39 // Hide the bubble if it is currently shown and the icon is hidden.
40 if (!model_
&& bubble_
)
41 bubble_
->GetWidget()->Hide();
44 void OpenPDFInReaderView::ShowBubble() {
49 bubble_
= new OpenPDFInReaderBubbleView(this, model_
);
50 views::BubbleDelegateView::CreateBubble(bubble_
);
51 bubble_
->GetWidget()->AddObserver(this);
52 bubble_
->GetWidget()->Show();
55 void OpenPDFInReaderView::GetAccessibleState(ui::AXViewState
* state
) {
56 state
->name
= l10n_util::GetStringUTF16(IDS_ACCNAME_OPEN_PDF_IN_READER
);
57 state
->role
= ui::AX_ROLE_BUTTON
;
60 bool OpenPDFInReaderView::OnMousePressed(const ui::MouseEvent
& event
) {
61 // Show the bubble on mouse release; that is standard button behavior.
65 void OpenPDFInReaderView::OnMouseReleased(const ui::MouseEvent
& event
) {
66 if (event
.IsOnlyLeftMouseButton() && HitTestPoint(event
.location()))
70 bool OpenPDFInReaderView::OnKeyPressed(const ui::KeyEvent
& event
) {
71 if (event
.key_code() != ui::VKEY_SPACE
&&
72 event
.key_code() != ui::VKEY_RETURN
) {
80 void OpenPDFInReaderView::OnWidgetDestroying(views::Widget
* widget
) {
84 bubble_
->GetWidget()->RemoveObserver(this);