Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / views / frame / web_app_left_header_view_ash.cc
blob4f7e18c6441590445fc65cf0d4bf06b7a0916536
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/toolbar/toolbar_model.h"
12 #include "chrome/browser/ui/views/frame/browser_view.h"
13 #include "content/public/browser/navigation_entry.h"
14 #include "grit/ash_resources.h"
15 #include "ui/views/layout/box_layout.h"
17 // static
18 const char WebAppLeftHeaderView::kViewClassName[] = "WebAppLeftHeaderView";
20 WebAppLeftHeaderView::WebAppLeftHeaderView(BrowserView* browser_view)
21 : browser_view_(browser_view) {
22 SetLayoutManager(
23 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
25 back_button_ =
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_);
33 location_icon_ =
34 new ash::FrameCaptionButton(this, ash::CAPTION_BUTTON_ICON_LOCATION);
35 AddChildView(location_icon_);
37 Update();
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();
78 else
79 NOTREACHED();
82 void WebAppLeftHeaderView::ShowWebsiteSettings() const {
83 content::WebContents* tab = browser_view_->GetActiveWebContents();
84 if (!tab)
85 return;
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("").
90 if (!nav_entry)
91 return;
93 chrome::ShowWebsiteSettings(browser_view_->browser(), tab,
94 nav_entry->GetURL(), nav_entry->GetSSL());