Commit 37aa2980 authored by Travis Skare's avatar Travis Skare Committed by Commit Bot

[QRCode Generator] Padding adjustment and Icon visibility changes.

Reduces dialog width and space below download button to spec.
Matches eligibility logic to send-tab-to-self (http-or-https)
Matches focus hide/show to STTS.

BUG=1077077,1082829

Change-Id: I0deee3f85d2ccc69190c2723e394584f8ee79588
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2218760Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarGayane Petrosyan <gayane@chromium.org>
Commit-Queue: Travis Skare <skare@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774580}
parent 1e0313e6
......@@ -63,7 +63,6 @@
#include "chrome/browser/sharing/click_to_call/click_to_call_context_menu_observer.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_metrics.h"
#include "chrome/browser/sharing/click_to_call/click_to_call_utils.h"
#include "chrome/browser/sharing/features.h"
#include "chrome/browser/sharing/shared_clipboard/shared_clipboard_context_menu_observer.h"
#include "chrome/browser/sharing/shared_clipboard/shared_clipboard_utils.h"
#include "chrome/browser/spellchecker/spellcheck_service.h"
......@@ -2634,18 +2633,14 @@ bool RenderViewContextMenu::IsQRCodeGeneratorEnabled() const {
if (!GetBrowser())
return false;
if (!base::FeatureList::IsEnabled(kSharingQRCodeGenerator))
return false;
if (browser_context_->IsOffTheRecord())
return false;
NavigationEntry* entry =
embedder_web_contents_->GetController().GetLastCommittedEntry();
if (!entry || !content::IsSavableURL(entry->GetURL()))
if (!entry)
return false;
return true;
bool incognito = browser_context_->IsOffTheRecord();
return qrcode_generator::QRCodeGeneratorBubbleController::
IsGeneratorAvailable(entry->GetURL(), incognito);
}
bool RenderViewContextMenu::IsRouteMediaEnabled() const {
......
......@@ -4,6 +4,7 @@
#include "chrome/browser/ui/qrcode_generator/qrcode_generator_bubble_controller.h"
#include "chrome/browser/sharing/features.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
......@@ -18,6 +19,21 @@ QRCodeGeneratorBubbleController::~QRCodeGeneratorBubbleController() {
HideBubble();
}
// static
bool QRCodeGeneratorBubbleController::IsGeneratorAvailable(const GURL& url,
bool in_incognito) {
if (in_incognito)
return false;
if (!base::FeatureList::IsEnabled(kSharingQRCodeGenerator))
return false;
if (!url.SchemeIsHTTPOrHTTPS())
return false;
return true;
}
// static
QRCodeGeneratorBubbleController* QRCodeGeneratorBubbleController::Get(
content::WebContents* web_contents) {
......
......@@ -26,6 +26,10 @@ class QRCodeGeneratorBubbleController
public:
~QRCodeGeneratorBubbleController() override;
// Returns whether the generator is available for a given page and
// state (incognito etc.).
static bool IsGeneratorAvailable(const GURL& url, bool in_incognito);
static QRCodeGeneratorBubbleController* Get(
content::WebContents* web_contents);
......
......@@ -176,8 +176,11 @@ const char* QRCodeGeneratorBubble::GetClassName() const {
}
void QRCodeGeneratorBubble::Init() {
set_margins(ChromeLayoutProvider::Get()->GetDialogInsetsForContentType(
views::CONTROL, views::CONTROL));
// Requesting TEXT for trailing prevents extra padding at bottom of dialog.
gfx::Insets insets =
ChromeLayoutProvider::Get()->GetDialogInsetsForContentType(views::CONTROL,
views::TEXT);
set_margins(insets);
// Internal IDs for column layout; no effect on UI.
constexpr int kQRImageColumnSetId = 0;
......@@ -215,12 +218,14 @@ void QRCodeGeneratorBubble::Init() {
// Text box to edit URL
views::ColumnSet* column_set_textfield =
layout->AddColumnSet(kTextFieldColumnSetId);
int textfield_min_width = ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_BUBBLE_PREFERRED_WIDTH) -
insets.left() - insets.right();
column_set_textfield->AddColumn(
views::GridLayout::FILL, // Fill text field horizontally.
views::GridLayout::CENTER, // Align center vertically, do not resize.
1.0, views::GridLayout::ColumnSize::kUsePreferred, 0,
ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_BUBBLE_PREFERRED_WIDTH));
textfield_min_width);
auto textfield_url = std::make_unique<views::Textfield>();
textfield_url->SetAccessibleName(l10n_util::GetStringUTF16(
IDS_BROWSER_SHARING_QR_CODE_DIALOG_URL_TEXTFIELD_ACCESSIBLE_NAME));
......
......@@ -12,6 +12,7 @@
#include "chrome/grit/generated_resources.h"
#include "components/omnibox/browser/omnibox_edit_model.h"
#include "components/omnibox/browser/omnibox_view.h"
#include "content/public/browser/browser_context.h"
#include "ui/base/l10n/l10n_util.h"
namespace qrcode_generator {
......@@ -53,12 +54,21 @@ void QRCodeGeneratorIconView::UpdateImpl() {
if (!omnibox_view)
return;
// TODO(skare): Fix show and re-hide conditions.
// Need this queried in more cases.
if (omnibox_view->model()->has_focus() &&
!omnibox_view->model()->user_input_in_progress()) {
if (!GetVisible())
if (!QRCodeGeneratorBubbleController::IsGeneratorAvailable(
web_contents->GetURL(),
web_contents->GetBrowserContext()->IsOffTheRecord())) {
return;
}
if (omnibox_view->model()->has_focus()) {
if (!omnibox_view->model()->user_input_in_progress() && !GetVisible()) {
SetVisible(true);
}
} else {
// Omnibox not focused.
if (GetVisible()) {
SetVisible(false);
}
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment