wm_overview_title.cc revision 4a5e2dc747d50c653511c68ccb2cfbfb740bd5a7
1// Copyright (c) 2010 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/chromeos/wm_overview_title.h" 6 7#include <vector> 8 9#include "app/x11_util.h" 10#include "base/string16.h" 11#include "base/utf_string_conversions.h" 12#include "chrome/browser/browser_window.h" 13#include "chrome/browser/chromeos/drop_shadow_label.h" 14#include "chrome/browser/chromeos/wm_ipc.h" 15#include "chrome/browser/chromeos/wm_overview_snapshot.h" 16#include "chrome/browser/ui/browser.h" 17#include "cros/chromeos_wm_ipc_enums.h" 18#include "third_party/skia/include/core/SkBitmap.h" 19#include "views/border.h" 20#include "views/grid_layout.h" 21#include "views/view.h" 22 23using std::vector; 24using views::ColumnSet; 25using views::GridLayout; 26using views::View; 27using gfx::Font; 28 29#if !defined(OS_CHROMEOS) 30#error This file is only meant to be compiled for ChromeOS 31#endif 32 33namespace chromeos { 34 35// The padding between the title and the URL, in pixels. 36static const int kVerticalPadding = 2; 37 38// This is the size (in pixels) of the drop shadow on the title and url text. 39static const int kDropShadowSize = 2; 40 41namespace { 42// Finds a font based on the base font that is no taller than the 43// given value (well, unless the font at size 1 is taller than the 44// given value). 45Font FindFontThisHigh(int pixels, Font base) { 46 Font font(base.GetFontName(), 1); 47 Font last_font = font; 48 while (font.GetHeight() < pixels) { 49 last_font = font; 50 font = font.DeriveFont(1, Font::BOLD); 51 } 52 return last_font; 53} 54} // Anonymous namespace 55 56WmOverviewTitle::WmOverviewTitle() 57 : WidgetGtk(TYPE_WINDOW), 58 title_label_(NULL), 59 url_label_(NULL) { 60} 61 62void WmOverviewTitle::Init(const gfx::Size& size, 63 WmOverviewSnapshot* snapshot) { 64 MakeTransparent(); 65 66 title_label_ = new DropShadowLabel(); 67 title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 68 title_label_->SetColor(SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF)); 69 title_label_->SetDropShadowSize(kDropShadowSize); 70 title_label_->SetFont(FindFontThisHigh(16, title_label_->font())); 71 72 url_label_ = new DropShadowLabel(); 73 url_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 74 url_label_->SetColor(SkColorSetARGB(0x80, 0xFF, 0xFF, 0xFF)); 75 url_label_->SetDropShadowSize(kDropShadowSize); 76 url_label_->SetFont(FindFontThisHigh(14, title_label_->font())); 77 78 // Create a new view to be the host for the grid. 79 View* view = new View(); 80 GridLayout* layout = new GridLayout(view); 81 view->SetLayoutManager(layout); 82 83 int title_cs_id = 0; 84 ColumnSet* columns = layout->AddColumnSet(title_cs_id); 85 columns->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, 86 GridLayout::FIXED, size.width(), 0); 87 88 layout->StartRow(0, title_cs_id); 89 layout->AddView(title_label_); 90 layout->StartRowWithPadding(1, title_cs_id, 0, kVerticalPadding); 91 layout->AddView(url_label_); 92 93 // Realize the widget. 94 WidgetGtk::Init(NULL, gfx::Rect(size)); 95 96 // Make the view the contents view for this widget. 97 SetContentsView(view); 98 99 // Set the window type 100 vector<int> params; 101 params.push_back(x11_util::GetX11WindowFromGtkWidget( 102 GTK_WIDGET(snapshot->GetNativeView()))); 103 WmIpc::instance()->SetWindowType( 104 GetNativeView(), 105 WM_IPC_WINDOW_CHROME_TAB_TITLE, 106 ¶ms); 107} 108 109void WmOverviewTitle::SetTitle(const string16& title) { 110 title_label_->SetText(UTF16ToWide(title)); 111} 112 113void WmOverviewTitle::SetUrl(const GURL& url) { 114 url_label_->SetURL(url); 115} 116} // namespace chromeos 117