Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(767)

Unified Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 1685763004: Fix various issues with popup/app window layout/drawing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup
Patch Set: Fix unittest Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/location_bar/location_bar_view.cc
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc
index 8d3719a417fef5a8a07fa07e510e836767eac2d4..7adaf3fb21df88758a56c51d7105faf07dcd19cf 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc
@@ -22,6 +22,7 @@
#include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
+#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#include "chrome/browser/translate/translate_service.h"
#include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h"
@@ -34,6 +35,7 @@
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/autofill/save_card_icon_view.h"
#include "chrome/browser/ui/views/browser_dialogs.h"
+#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h"
#include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
#include "chrome/browser/ui/views/location_bar/keyword_hint_view.h"
@@ -163,6 +165,15 @@ LocationBarView::~LocationBarView() {
////////////////////////////////////////////////////////////////////////////////
// LocationBarView, public:
+// static
+SkColor LocationBarView::GetBorderColor(bool incognito) {
+ return color_utils::AlphaBlend(
+ SkColorSetA(kBorderColor, SK_AlphaOPAQUE),
+ ThemeProperties::GetDefaultColor(ThemeProperties::COLOR_TOOLBAR,
+ incognito),
+ SkColorGetA(kBorderColor));
+}
+
void LocationBarView::Init() {
// We need to be in a Widget, otherwise GetNativeTheme() may change and we're
// not prepared for that.
@@ -193,7 +204,9 @@ void LocationBarView::Init() {
}
// Shrink large fonts to make them fit.
// TODO(pkasting): Stretch the location bar instead in this case.
- const int location_height = GetInternalHeight(true);
+ const int vertical_padding = GetVerticalEdgeThicknessWithPadding(false);
+ const int location_height =
+ std::max(GetPreferredSize().height() - (vertical_padding * 2), 0);
font_list = font_list.DeriveWithHeightUpperBound(location_height);
// Determine the font for use inside the bubbles. The bubble background
@@ -201,8 +214,7 @@ void LocationBarView::Init() {
const int kBubbleInteriorVerticalPadding =
ui::MaterialDesignController::IsModeMaterial() ? 2 : 1;
const int bubble_padding =
- GetEdgeThickness() +
- GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING) +
+ GetVerticalEdgeThicknessWithPadding(true) +
kBubbleInteriorVerticalPadding;
const int bubble_height = GetPreferredSize().height() - (bubble_padding * 2);
gfx::FontList bubble_font_list =
@@ -457,12 +469,6 @@ gfx::Point LocationBarView::GetLocationBarAnchorPoint() const {
return point;
}
-int LocationBarView::GetInternalHeight(bool use_preferred_size) {
- int total_height =
- use_preferred_size ? GetPreferredSize().height() : height();
- return std::max(total_height - (VerticalPadding() * 2), 0);
-}
-
void LocationBarView::GetOmniboxPopupPositioningInfo(
gfx::Point* top_left_screen_coord,
int* popup_width,
@@ -474,8 +480,7 @@ void LocationBarView::GetOmniboxPopupPositioningInfo(
*popup_width = parent()->width();
gfx::Rect location_bar_bounds(bounds());
- location_bar_bounds.Inset(GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS),
- 0);
+ location_bar_bounds.Inset(GetHorizontalEdgeThickness(), 0);
*left_margin = location_bar_bounds.x();
*right_margin = *popup_width - location_bar_bounds.right();
}
@@ -512,9 +517,7 @@ gfx::Size LocationBarView::GetPreferredSize() const {
// Compute minimum height.
gfx::Size min_size;
if (ui::MaterialDesignController::IsModeMaterial() || is_popup_mode_) {
- const int height = GetLayoutConstant(LOCATION_BAR_HEIGHT);
- const int edge_thickness = views::NonClientFrameView::kClientEdgeThickness;
- min_size.set_height(height - (is_popup_mode_ ? (2 * edge_thickness) : 0));
+ min_size.set_height(GetLayoutConstant(LOCATION_BAR_HEIGHT));
} else {
min_size = border_painter_->GetMinimumSize();
}
@@ -527,7 +530,7 @@ gfx::Size LocationBarView::GetPreferredSize() const {
const int padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
// Compute width of omnibox-leading content.
- const int edge_thickness = GetEdgeThickness();
+ const int edge_thickness = GetHorizontalEdgeThickness();
int leading_width = edge_thickness;
if (ShouldShowKeywordBubble()) {
// The selected keyword view can collapse completely.
@@ -570,7 +573,7 @@ void LocationBarView::Layout() {
keyword_hint_view_->SetVisible(false);
const int item_padding = GetLayoutConstant(LOCATION_BAR_HORIZONTAL_PADDING);
- const int edge_thickness = GetEdgeThickness();
+ const int edge_thickness = GetHorizontalEdgeThickness();
int trailing_edge_item_padding = 0;
if (!ui::MaterialDesignController::IsModeMaterial()) {
trailing_edge_item_padding =
@@ -589,14 +592,13 @@ void LocationBarView::Layout() {
// to position our child views in this case, because other things may be
// positioned relative to them (e.g. the "bookmark added" bubble if the user
// hits ctrl-d).
- const int bubble_vertical_padding =
- edge_thickness + GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING);
+ const int bubble_vertical_padding = GetVerticalEdgeThicknessWithPadding(true);
const int bubble_height =
std::max(height() - (bubble_vertical_padding * 2), 0);
const int bubble_horizontal_padding =
GetLayoutConstant(LOCATION_BAR_BUBBLE_HORIZONTAL_PADDING);
- const int location_height = GetInternalHeight(false);
- const int vertical_padding = VerticalPadding();
+ const int vertical_padding = GetVerticalEdgeThicknessWithPadding(false);
+ const int location_height = std::max(height() - (vertical_padding * 2), 0);
location_icon_view_->SetLabel(base::string16());
location_icon_view_->SetBackground(false);
@@ -845,12 +847,22 @@ int LocationBarView::IncrementalMinimumWidth(views::View* view) const {
view->GetMinimumSize().width()) : 0;
}
-int LocationBarView::GetEdgeThickness() const {
+int LocationBarView::GetHorizontalEdgeThickness() const {
return is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS);
}
-int LocationBarView::VerticalPadding() const {
- return is_popup_mode_ ? 0 : GetLayoutConstant(LOCATION_BAR_VERTICAL_PADDING);
+int LocationBarView::GetVerticalEdgeThickness() const {
+ if (ui::MaterialDesignController::IsModeMaterial())
+ return GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS);
+ return is_popup_mode_ ? views::NonClientFrameView::kClientEdgeThickness
+ : GetLayoutConstant(LOCATION_BAR_BORDER_THICKNESS);
+}
+
+int LocationBarView::GetVerticalEdgeThicknessWithPadding(
+ bool for_bubble) const {
+ return GetVerticalEdgeThickness() +
+ GetLayoutConstant(for_bubble ? LOCATION_BAR_BUBBLE_VERTICAL_PADDING
+ : LOCATION_BAR_VERTICAL_PADDING);
}
void LocationBarView::RefreshLocationIcon() {
@@ -1271,12 +1283,10 @@ void LocationBarView::OnPaint(gfx::Canvas* canvas) {
// border images are meant to rest atop the toolbar background and parts atop
// the omnibox background, so we can't just blindly fill our entire bounds.
gfx::Rect bounds(GetContentsBounds());
- const int edge_thickness = GetEdgeThickness();
- bounds.Inset(edge_thickness, edge_thickness);
+ bounds.Inset(GetHorizontalEdgeThickness(),
+ is_popup_mode_ ? 0 : GetVerticalEdgeThickness());
SkColor background_color(GetColor(BACKGROUND));
- if (is_popup_mode_) {
- canvas->FillRect(bounds, background_color);
- } else {
+ if (!is_popup_mode_) {
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
paint.setColor(background_color);
@@ -1284,7 +1294,13 @@ void LocationBarView::OnPaint(gfx::Canvas* canvas) {
canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint);
// The border itself will be drawn in PaintChildren() since it includes an
// inner shadow which should be drawn over the contents.
+ return;
}
+
+ canvas->FillRect(bounds, background_color);
+ const SkColor border_color = GetBorderColor(profile()->IsOffTheRecord());
+ BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, false);
+ BrowserView::Paint1pxHorizontalLine(canvas, border_color, bounds, true);
}
void LocationBarView::PaintChildren(const ui::PaintContext& context) {
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/browser/ui/views/toolbar/toolbar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698