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/pdf/pdf_tab_helper.h"
8 #include "chrome/browser/ui/views/open_pdf_in_reader_bubble_view.h"
9 #include "grit/generated_resources.h"
10 #include "grit/theme_resources.h"
11 #include "ui/accessibility/ax_view_state.h"
12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/views/widget/widget.h"
16 OpenPDFInReaderView::OpenPDFInReaderView() : bubble_(NULL
), model_(NULL
) {
17 SetAccessibilityFocusable(true);
18 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
19 IDR_OMNIBOX_PDF_ICON
));
20 SetTooltipText(l10n_util::GetStringUTF16(IDS_PDF_BUBBLE_OPEN_IN_READER_LINK
));
23 OpenPDFInReaderView::~OpenPDFInReaderView() {
25 bubble_
->GetWidget()->RemoveObserver(this);
28 void OpenPDFInReaderView::Update(content::WebContents
* web_contents
) {
31 PDFTabHelper
* pdf_tab_helper
= PDFTabHelper::FromWebContents(web_contents
);
32 model_
= pdf_tab_helper
->open_in_reader_prompt();
38 void OpenPDFInReaderView::ShowBubble() {
43 bubble_
= new OpenPDFInReaderBubbleView(this, model_
);
44 views::BubbleDelegateView::CreateBubble(bubble_
);
45 bubble_
->GetWidget()->AddObserver(this);
46 bubble_
->GetWidget()->Show();
49 void OpenPDFInReaderView::GetAccessibleState(ui::AXViewState
* state
) {
50 state
->name
= l10n_util::GetStringUTF16(IDS_ACCNAME_OPEN_PDF_IN_READER
);
51 state
->role
= ui::AX_ROLE_BUTTON
;
54 bool OpenPDFInReaderView::OnMousePressed(const ui::MouseEvent
& event
) {
55 // Show the bubble on mouse release; that is standard button behavior.
59 void OpenPDFInReaderView::OnMouseReleased(const ui::MouseEvent
& event
) {
60 if (event
.IsOnlyLeftMouseButton() && HitTestPoint(event
.location()))
64 bool OpenPDFInReaderView::OnKeyPressed(const ui::KeyEvent
& event
) {
65 if (event
.key_code() != ui::VKEY_SPACE
&&
66 event
.key_code() != ui::VKEY_RETURN
) {
74 void OpenPDFInReaderView::OnWidgetDestroying(views::Widget
* widget
) {
78 bubble_
->GetWidget()->RemoveObserver(this);