1 // Copyright 2014 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/frame/web_app_left_header_view_ash.h"
7 #include "ash/frame/caption_buttons/frame_caption_button.h"
8 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/ui/browser_commands.h"
11 #include "chrome/browser/ui/views/frame/browser_view.h"
12 #include "components/toolbar/toolbar_model.h"
13 #include "content/public/browser/navigation_entry.h"
14 #include "grit/ash_resources.h"
15 #include "ui/views/layout/box_layout.h"
18 const char WebAppLeftHeaderView::kViewClassName
[] = "WebAppLeftHeaderView";
20 WebAppLeftHeaderView::WebAppLeftHeaderView(BrowserView
* browser_view
)
21 : browser_view_(browser_view
) {
23 new views::BoxLayout(views::BoxLayout::kHorizontal
, 0, 0, 0));
26 new ash::FrameCaptionButton(this, ash::CAPTION_BUTTON_ICON_BACK
);
27 back_button_
->SetImages(
28 ash::CAPTION_BUTTON_ICON_BACK
, ash::FrameCaptionButton::ANIMATE_NO
,
29 IDR_AURA_WINDOW_CONTROL_ICON_BACK
, IDR_AURA_WINDOW_CONTROL_BACKGROUND_H
,
30 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P
);
31 AddChildView(back_button_
);
34 new ash::FrameCaptionButton(this, ash::CAPTION_BUTTON_ICON_LOCATION
);
35 AddChildView(location_icon_
);
40 WebAppLeftHeaderView::~WebAppLeftHeaderView() {
43 void WebAppLeftHeaderView::Update() {
44 int icon_resource
= browser_view_
->browser()->toolbar_model()->GetIcon();
45 location_icon_
->SetImages(ash::CAPTION_BUTTON_ICON_LOCATION
,
46 ash::FrameCaptionButton::ANIMATE_NO
, icon_resource
,
47 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H
,
48 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P
);
50 back_button_
->SetState(
51 chrome::IsCommandEnabled(browser_view_
->browser(), IDC_BACK
)
52 ? views::Button::STATE_NORMAL
53 : views::Button::STATE_DISABLED
);
56 void WebAppLeftHeaderView::SetPaintAsActive(bool active
) {
57 // TODO(benwells): Check that the disabled and inactive states should be
58 // drawn in the same way.
59 back_button_
->set_paint_as_active(
60 active
&& chrome::IsCommandEnabled(browser_view_
->browser(), IDC_BACK
));
61 location_icon_
->set_paint_as_active(active
);
64 views::View
* WebAppLeftHeaderView::GetLocationIconView() const {
65 return location_icon_
;
68 const char* WebAppLeftHeaderView::GetClassName() const {
69 return kViewClassName
;
72 void WebAppLeftHeaderView::ButtonPressed(views::Button
* sender
,
73 const ui::Event
& event
) {
74 if (sender
== back_button_
)
75 chrome::ExecuteCommand(browser_view_
->browser(), IDC_BACK
);
76 else if (sender
== location_icon_
)
77 ShowWebsiteSettings();
82 void WebAppLeftHeaderView::ShowWebsiteSettings() const {
83 content::WebContents
* tab
= browser_view_
->GetActiveWebContents();
87 // Important to use GetVisibleEntry to match what's showing in the title area.
88 content::NavigationEntry
* nav_entry
= tab
->GetController().GetVisibleEntry();
89 // The visible entry can be NULL in the case of window.open("").
93 SecurityStateModel
* security_model
= SecurityStateModel::FromWebContents(tab
);
94 DCHECK(security_model
);
96 chrome::ShowWebsiteSettings(browser_view_
->browser(), tab
,
98 security_model
->GetSecurityInfo());