blob: 182015b168b0949c90af23cda9cf8c13875814d8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/views/location_bar/selected_keyword_view.h"
#include "app/l10n_util.h"
#include "base/logging.h"
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/browser/location_bar_util.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/views/location_bar/keyword_hint_view.h"
#include "grit/generated_resources.h"
SelectedKeywordView::SelectedKeywordView(const int background_images[],
int contained_image,
const SkColor& color,
Profile* profile)
: IconLabelBubbleView(background_images, contained_image, color),
profile_(profile) {
full_label_.SetVisible(false);
partial_label_.SetVisible(false);
}
SelectedKeywordView::~SelectedKeywordView() {
}
void SelectedKeywordView::SetFont(const gfx::Font& font) {
IconLabelBubbleView::SetFont(font);
full_label_.SetFont(font);
partial_label_.SetFont(font);
}
gfx::Size SelectedKeywordView::GetPreferredSize() {
gfx::Size size(GetNonLabelSize());
size.Enlarge(full_label_.GetPreferredSize().width(), 0);
return size;
}
gfx::Size SelectedKeywordView::GetMinimumSize() {
gfx::Size size(GetNonLabelSize());
size.Enlarge(partial_label_.GetMinimumSize().width(), 0);
return size;
}
void SelectedKeywordView::Layout() {
SetLabel((width() == GetPreferredSize().width()) ?
full_label_.GetText() : partial_label_.GetText());
IconLabelBubbleView::Layout();
}
void SelectedKeywordView::SetKeyword(const std::wstring& keyword) {
keyword_ = keyword;
if (keyword.empty())
return;
DCHECK(profile_);
if (!profile_->GetTemplateURLModel())
return;
bool is_extension_keyword;
const std::wstring short_name = profile_->GetTemplateURLModel()->
GetKeywordShortName(keyword, &is_extension_keyword);
int message_id = is_extension_keyword ?
IDS_OMNIBOX_EXTENSION_KEYWORD_TEXT : IDS_OMNIBOX_KEYWORD_TEXT;
full_label_.SetText(l10n_util::GetStringF(message_id, short_name));
const std::wstring min_string(
location_bar_util::CalculateMinString(short_name));
partial_label_.SetText(min_string.empty() ?
full_label_.GetText() :
l10n_util::GetStringF(message_id, min_string));
}
|